DateDiff to show hours and mins

echo0001

Registered User.
Local time
Today, 11:24
Joined
Aug 30, 2008
Messages
55
hello all,

Basically I want a way to get the number of hours between two date/times, but with hours and minutes.

Currently i use
Code:
DateDiff("h",[Check In/Out].[Check In],[Check In/Out].[Check Out]) AS Hours
But this only returns the number of hours.

How do you get it to return the minutes as well in he same field?

Cheers
 
DateDiff("n",[Check In/Out].[Check In],[Check In/Out].[Check Out]) \ 60 & " Hours " & DateDiff("n",[Check In/Out].[Check In],[Check In/Out].[Check Out]) MOD 60 & " Minutes" As ElapsedTime
 
Last edited:
Oh, and make sure you use the backslash \

for dividing by 60 as that yields the integer portion of the result without decimals.

the MOD 60 returns the remainder
 
DateDiff() will only return a result in one unit ie. either hours or minutes etc.

What you will need to do is get the result in say minutes and then reduce that to hours and minutes by dividing the result by 60. Something like the following would do the trick;
Code:
Dim Period as Double

Period = DateDiff("n",[Check In/Out].[Check In],[Check In/Out].[Check Out]) 

Me.PeriodHours = Int(Period/60)
Me.PeriodMinutes = (Period / 60 - Int(Period / 60)) * 60

Where Me.PeriodHours and Me.PeriodMinutes are unbound fields on your form.

You could use;
Code:
Me.PeriodTime = Int(Period/60) & ":" & (Period / 60 - Int(Period / 60)) * 60
If you want to show it in the format of 1:20
 
Too slow (got distracted half way through my post) :( beaten to the punch by Bob
 
Too slow (got distracted half way through my post) :( beaten to the punch by Bob
Not only that but with a better solution :D

(it's just that I've written that one so many times I can almost do it in my sleep)

Remember the \ operator gives you the integer value of the result and the mod operator gives you the remainder. They simplify things a lot sometimes.
 

Users who are viewing this thread

Back
Top Bottom