Time difference

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

I am trying to find difference between two time values in hours. I have
tried the following?

? dateDiff("h", #23:00:00#, #23:00:00#) gives 0 as expected.

? dateDiff("h", #00:00:00#, #23:00:00#) gives 23??? should it not be 1 as
00:00:00 (12 midnight) is only one hour after 23:00:00 (11 pm)?

? dateDiff("h", #01:00:00#, #23:00:00#) gives 22. Should it not be 2 as
01:00:00 (1 am) is two hour after 23:00:00 (11 pm)?

What is going on? How can I get the desired time difference values?

Thanks

Regards
 
John said:
Hi

I am trying to find difference between two time values in hours. I have
tried the following?

? dateDiff("h", #23:00:00#, #23:00:00#) gives 0 as expected.

? dateDiff("h", #00:00:00#, #23:00:00#) gives 23??? should it not be 1 as
00:00:00 (12 midnight) is only one hour after 23:00:00 (11 pm)?

? dateDiff("h", #01:00:00#, #23:00:00#) gives 22. Should it not be 2 as
01:00:00 (1 am) is two hour after 23:00:00 (11 pm)?

What is going on? How can I get the desired time difference values?

You're reading the parameters backwards.

In the second example, it reads:

23:00 - 0:00 = 23 hours

In the third example, it reads:

23:00 - 1:00 = 22 hours
 
Hi

I am trying to find difference between two time values in hours. I have
tried the following?

? dateDiff("h", #23:00:00#, #23:00:00#) gives 0 as expected.

? dateDiff("h", #00:00:00#, #23:00:00#) gives 23??? should it not be 1 as
00:00:00 (12 midnight) is only one hour after 23:00:00 (11 pm)?

? dateDiff("h", #01:00:00#, #23:00:00#) gives 22. Should it not be 2 as
01:00:00 (1 am) is two hour after 23:00:00 (11 pm)?

What is going on? How can I get the desired time difference values?

These results are exactly correct. The second argument to DateDiff is
the start time, the third the end time; and 23:00:00 is indeed 23
hours after midinght on the same day.

Note that an Access Date/Time value, regardless of format, is stored
as a Double Float number, a count of days and fractions of a day
(times) since midnight, December 30, 1899. #23:00:00# is actually
stored as 0.95833333333333333, and corresponds to
#12/30/1899 23:00:00# - all pure time values are times on that
long-ago day.

If you want the time differnce between 11pm tonight and 1am tomorrow
morning you should consider storing the date and time together in the
field. DateDiff("h", #5/30/2004 23:00:00#, #5/31/2004 02:00:00#) will
indeed return 3 hours, not -21.
 
Back
Top