Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can DateDiff give hours and minutes

Status
Not open for further replies.

medium

MIS
Aug 28, 2002
30
US
Does anyone know if the DateDiff function can give hours and minutes?

For example, the following code will give me the hours between dtmDown and dtmUp, but it will only give me a whole number. Is there a way to get hours.minutes?

DateDiff(Interval:="h", Date1:=dtmDown, _
Date2:=dtmUp)

Thanks in advance.

 
Hi,
you could use the interval "n" which would return the total minutes elapsed.

DateDiff("n",dtmDown,dtmUp)

Then divide this by 60 to get the hours and work out the minutes. Seeing as this is in the VBA Coding forum I'll assume you're not using it a query, so you could use the Mod operator (which returns the remainder of a division operation). See below:

dim nTotalMinutes as integer, nHours as integer, nMinutes as integer

nTotalMinutes=DateDiff("n",dtmDown,dtmUp)
nHours=nTotalMinutes\60
nMinutes=nHours Mod 60

Please note the backslash for division instead of forward-slash as this will return you the whole number of hours instead of a fraction.
I hope I've made sense!Good luck.

 
Thanks SarahG :)

I guess I sometimes think the code has a specific function for everything. If you will, I missed the individual trees because I was looking at the forest.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top