Calculated date fields

W

work

I have a discrepancy with my date time fields - hope someone can help:)

Background
I've created two calulated fields to subtract dates. The first field is a
direct subtraction ie. =[date/time1]-[date/time2]

The second uses the following formula
=DateDiff("h",[date/time1],[date/time2]

I've combined the two fields to calulate total hours over a period of time.

Problem
Some of the calculations using the second formula adds an extra hour to my
times. It doesn't happen in all cases, so I can only guess that the formula
"rounds up" to hours in some cases. Is there a way to prevent this from
happening.

Please HELP
 
V

Van T. Dinh

From A2K Debug window:

?DateDiff("h", #11:59:59#, #12:00:00#)
1

1 second = 1 hour???

The problem is that DateDiff with "h" will only count the "raw" hours. You
see from the above 12 - 11 is 1 (hour). That's how DateDiff works.

If you want more accuracy, use DateDiff to get the difference minutes (or
second) and then divide the difference by 60 (or 3600) to get the "decimal"
hours. Once you get the minutes or seconds, you can manipulate it whichever
way you want.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top