returning difference in times

  • Thread starter Thread starter Ben
  • Start date Start date
B

Ben

I am trying to get the time differences between two
times. When I subtract I am getting odd results.

Such as 9/22/2004 9:30:14 AM - 9/22/2004 9:30:10 AM giving
4.62962925666943E-05

Or

9/22/2004 9:13:11 AM - 9/22/2004 9:12:36 AM giving
0.000405092592700385

How can I get the answer in usable time, for instance 14
seconds in first example, 75 seconds in second?

I need to test for greater than certain number of hours
for various types.
 
Hi Ben,

Assuming this is an Access-related problem, you would use the DateDiff
function. DateDiff() can be used to calculate the difference in time
between 2 date fields:

TimeElapsed: DateDiff("h", [OrderDate], [ShippedDate])

This would return the difference in hours. You can specify different
intervals (minutes, seconds etc.) if you prefer.

DateDiff() can also calculate the difference between 2 "hardwired"
dates:

TimeElapsed: DateDiff("h", #9/22/2004 9:12:36 AM#, #9/22/2004 5:00:00
AM#)

Incidentally, Access stores date/time data as double-precision,
floating-point numbers of up to 15 decimal places. The number to the
left of the decimal represents the date; numbers on the right represent
time. You can view this by opening any module in your db and opening the
Debug window (Ctrl + G). For example, to see what "4.62962925666943E-05"
translates to in human-readable time, type

? CVDate(4.62962925666943E-05)

into the Immediate pane. In the above example, Access should return
12:00:04 AM. Just for giggles, you can reverse the process by typing

? Cdbl(#12:00:04 AM#)

in the Immediate pane.

hth,

LeAnne
 
The difference between dates is in units of days. Multiply by 24 to get the
difference in hours, by 24*60 to get the difference in minutes, or by
24*60*60 to get the difference in seconds.
 
Back
Top