Date/time calculations

S

Shelby

I am creating a database with a Date/Time to Administrator
field, and a Date/Time to Analyst field. I have these
fields formatted as ddd", "dd mmm yyyy hh:nn so that I can
capture both the day and hour in the same field. I need
to be able to calculate the difference in these two fields
as a record of hours and days - I'm tracking turnaround,
and it's not always a matter of hours, sometimes it might
be 3.5 hours, sometimes it might be 1 day and 3.5 hours.
I'm using the DateDiff function in a query, but I need to
know how to make it display the results in days and hours,
and not a round day (I'm getting 0 for a turnaround of a
few hours, and 1 for anything over a day). Is there a way
to do this?
 
W

Wayne Morgan

Find the difference to the smallest unit you will need using DateDiff then calculate it
back up to what you want.

For example, if you want hours and minutes, find the difference in minutes then calculate
hours and remaining minutes.

intMinutes = DateDiff("n", FirstDate/Time, SecondDate/Time)
intHours = Int(intMinutes / 60)
intRemainingMinutes = intMinutes Mod 60
strElapsedTime = intHours & " hours and " & intRemainingMinutes & " minutes"
 

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