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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date difference calculation

Status
Not open for further replies.

tuddys

Technical User
Aug 22, 2002
2
US
Somewhat new to access reporting. I need to compare two date/time stamps format [mm/dd/yyyy hh:mm:ss am], and return the total hours or minutes between the two dates. Is this possible, and if so what is the format? thanks for any help!
tuddys
 
Try this:

DateDiff("h",[test],[test2])

where test is your first date and test2 is your second date

"h" will get the hours between test and test2 J. Jones
jjones@cybrtyme.com
 
"n" (in place of "h") will return the minutes.

It the times are GUARNTEED to be less that 24H, you can just use Format ((EndTim - StrtTime), "Short Time"), as in:


Code:
EndTime = Now + 0.25
StrtTime = Now
LapsedTime = Format((EndTime - StrtTime), "Short time")
? LapsedTime
05:59

Note: the 0.25 represents 1/4 of a day or 6 hours. The 05:59 occurs as it took me a while to type the StrtTime = line.

To use this approach, you MUST be certain that the 'lapsedtime' will be less than one full day (24 Hours) - or check for that possability and adjust the results as necessary. the "Short time" format will ignore any full days! Consider the following:

Code:
ThisTime = Now
ThatTime = Now + 1.25
LapsedTime = Format((Thattime - thistime), "Short time")
? Lapsedtime
06:00

Here, I have essientially the SAME results even thpough the difference is one day more htan the previous example.



MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Thanks to both of you for the help!

tuddys
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top