View Full Version : Amount of time between 2 dates


hbrems
11-23-2007, 02:30 AM
Dear all,

in my table I have the following fields:

- fldstartdate
- fldstarttime

- fldenddate
- fldendtime

Can I calculate the time that is between those variables using an expression?

fldenddate.fldendtime - fldstartdate.fldstarttime = "x days and x minutes"

Kind regards,
Hans B.

RuralGuy
11-23-2007, 03:33 AM
This link should get you started: Calculate differences in time (http://www.mvps.org/access/datetime/date0004.htm)
Are you aware of the fact that Now() stores both Date *and* Time and saves disk space and cpu cycles.

hbrems
11-23-2007, 04:57 AM
Are you aware of the fact that Now() stores both Date *and* Time and saves disk space and cpu cycles.

No, I wasn't. That's a very useful remark. I guess it will also make my calculations easier with 2 fields (fldstart & fldend) instead of splitting them up.

Jon K
11-23-2007, 05:02 AM
Can I calculate the time that is between those variables using an expression?

fldenddate.fldendtime - fldstartdate.fldstarttime = "x days and x minutes"

Since date/time fields are internally numbers, you can calculate the elapsed time like this:
(fldenddate+fldendtime) - (fldstartdate+fldstarttime)

The integer of the above expression is the number of days and you can use the Format() function to extract the hours, minutes and seconds from the expression.

See the query in the attached database.
.

hbrems
11-23-2007, 06:01 AM
Thanks Jon. That was the initial solution that I was looking for! :)