The first thing is to remember that an "elapsed time" is NOT a Date/Time
value. Next, you have to decide how finely you want it reported. If you want
it down to minutes, then calculate the difference in seconds. If you want it
down to hours, then calculate the difference in minutes. Once you have the
difference, format the value as desired. For instance, if you want days,
hours, and minutes then find the difference in seconds and format it as
days, hours and minutes.
To find the difference, use the DateDiff function. This will accept the Date
and Time as a single item, so you may need to concatenate them together if
they are in separate fields.
Example:
Dim ElapsedTimeInSeconds As Long
ElapsedTimeInSeconds = DateDiff("s", "#" & [StartDate] & " " & [StartTime] &
"#", "#" & [EndDate] & " " & [EndTime] & "#")
The #'s are date/time delimiters, similar to using quotes for strings.
To format seconds as Days:Hours:Minutes:
strElapsedTime = ElapsedTimeInSeconds \ 86400 & Format((ElapsedTimeInSeconds
Mod 86400) / 86400, ":hh:nn")
This will truncate the seconds, so 1m59s will show as 1m. If the value was
90,501 seconds, the above would return 1:01:08 for 1 day, 1 hour, 8 minutes.
If you want seconds show also, change the string in the format expression to
":hh:nn:ss".
If you're wondering where 86,400 comes from, it is the number of seconds in
a day. The largest possible long integer (2,147,483,648) gives over 24,000
days when counting in seconds.
--
Wayne Morgan
MS Access MVP
Cassandra said:
I have a table set up where we enter the start date and start time, follow
up
date and follow up time as well as the close date and close time. How do
I
calculate the elapsed time from start to follow up and/or to close?