Problem Subtracting Dates to get time

D

Drew

I don't see my problem. Here is the code:
[Total Task Time].Value = Format(DateDiff("n", [Date/Time Out],
[Date/Time In]) / 60, "hh:mm:ss")

Here is an example of what I'm getting:
Date/Time In: 11/17/2006 1:44:52PM
Date/Time Out: 11/17/2006 2:13:02 PM
Total Task Time: 11:36:00


Any ideas why this isn't working correctly?
 
D

Drew

Well, the time out and time in should have been switched, but it's
still not working correctly.
 
D

Drew

Ok, my math was wrong, sorry for this post it was pretty much useless
since I could have worked it through myself with a little thinking.
Final code if anyone was wondering:

[Total Task Time].Value = Format(DateDiff("n", [Date/Time In],
[Date/Time Out]) / (60 * 24), "hh:mm")
Well, the time out and time in should have been switched, but it's
still not working correctly.
I don't see my problem. Here is the code:
[Total Task Time].Value = Format(DateDiff("n", [Date/Time Out],
[Date/Time In]) / 60, "hh:mm:ss")

Here is an example of what I'm getting:
Date/Time In: 11/17/2006 1:44:52PM
Date/Time Out: 11/17/2006 2:13:02 PM
Total Task Time: 11:36:00


Any ideas why this isn't working correctly?
 
M

Marshall Barton

Drew said:
I don't see my problem. Here is the code:
[Total Task Time].Value = Format(DateDiff("n", [Date/Time Out],
[Date/Time In]) / 60, "hh:mm:ss")

Here is an example of what I'm getting:
Date/Time In: 11/17/2006 1:44:52PM
Date/Time Out: 11/17/2006 2:13:02 PM
Total Task Time: 11:36:00


You have the two times backwards so the difference would be
negative.

The difference is in minutes, not a date/time, so you can
not use a date/time format.

Try this:

[Total Task Time] = DateDiff("n",[Date/Time In], [Date/Time
Out]) \ 60 & Format(DateDiff("n",[Date/Time In], [Date/Time
Out]) Mod 60, "\:00")

Note that the result in [Total Task Time] is a text string,
not a date/time nor a number.
 
M

Marshall Barton

Drew said:
Ok, my math was wrong, sorry for this post it was pretty much useless
since I could have worked it through myself with a little thinking.
Final code if anyone was wondering:

[Total Task Time].Value = Format(DateDiff("n", [Date/Time In],
[Date/Time Out]) / (60 * 24), "hh:mm")


That doesn't quite work either. The format code for minutes
is "n", "m" is for months. Besides, multiplying by 60*24
converts the number of minutes to simething taht is no
meaninful as a time.

Please try my earlier expression.
 
Top