[AccessD] datediff & format

Gustav Brock gustav at cactus.dk
Fri May 26 05:16:36 CDT 2017


Hi Kostas

You can use this function:

<code>
Public Function FormatHourMinute( _
  ByVal datTime As Date, _
  Optional ByVal strSeparator As String = ":") _
  As String

' Returns count of days, hours and minutes of datTime
' converted to hours and minutes as a formatted string
' with an optional choice of time separator.
'
' Example:
'   datTime: #10:03# + #20:01#
'   returns: 30:04
'
' 2005-02-05. Cactus Data ApS, CPH.

  Dim strHour       As String
  Dim strMinute     As String
  Dim strHourMinute As String

  strHour = CStr(Fix(datTime) * 24 + Hour(datTime))
  ' Add leading zero to minute count when needed.
  strMinute = Right("0" & CStr(Minute(datTime)), 2)
  strHourMinute = strHour & strSeparator & strMinute

  FormatHourMinute = strHourMinute

End Function
</code>

    TotalTime: FormatHourMinute(Sum([TimeOut]-[TimeIn]))

/gustav
________________________________________
Fra: AccessD <accessd-bounces at databaseadvisors.com> på vegne af Kostas Konstantinidis <kost36 at otenet.gr>
Sendt: 26. maj 2017 12:05:32
Til: 'Access Developers discussion and problem solving'
Emne: Re: [AccessD] datediff & format

Hi Stuart,
I guess I need both of them while I need extra calculation for weekly and
monthly sum

Thanks
/kostas

-----Original Message-----
From: AccessD [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of
Stuart McLachlan
Sent: Friday, May 26, 2017 12:51 PM
To: Access Developers discussion and problem solving
<accessd at databaseadvisors.com>
Subject: Re: [AccessD] datediff & format

Is it always within a single day?
or
Can it roll over midnight?  i.e. Can TimeIn be greater than TimeOut?
Can it exceed 24 hours?  If so, do you want 1:02:30 or 26:30 ?

--
Stuart


On 26 May 2017 at 11:55, Kostas Konstantinidis wrote:

> Hi all,
> In a time tracking I use the datediff
> hours: (DateDiff("";[TimeIn];[TimeOut]))/60
>
> but what I really need is to track the time difference result in
> format as hh:mm
>
> Could anyone help please?
> Thanks
> /kostas


More information about the AccessD mailing list