DateDiff Function

  • Thread starter Thread starter Ant
  • Start date Start date
A

Ant

I am having a bit of trouble with the Datediff function. I have two fields
Start_Time and End_Time I want to use the DateDiff command to calculate the
difference between the two times ( answer to be in hours and mins ) although
DateDiff(“h”,[Start_Time],[End_Time]) gives me the number of hours and
DateDiff(“n”,[Start_Time],[End_Time]) gives me minuets how can I get the
correct hours and mins together in ideally one text box but two would be OK.



E.g. Start Time = 9:00 AM

End Time = 11:15 AM

Answer = 2h 15min



All I can get is ether 2h or 135min



Thanks for any help
 
If you simply subtract the two numbers:
EndTime - StartTime
and you format the answer as Medium Date, you should get your answer.
 
Ant,

Where are you using this? On a form? In a qurey? In a report? (you
mentioned "text box", sounds like a form)

How exactly do you want the answer? Is "2:15" okay or does in need to be
"2h 15min"?

If "2:15" is okay, I would first try formatting the text box as "short time"
and then I would subtract the 2 fields:

= [End_Time] - [Start_Time]

I would think Access would be able to use the date/time serial numbers in
calculations.

If you need "2h 15min" and are familiar with using code in VBA, I came up
with some code that will display the amount of time living at a residence as
"x Years y Months". I can post that code and help you adapt it for your
use.

Conan Kelly
 
I am having a bit of trouble with the Datediff function. I have two fields
Start_Time and End_Time I want to use the DateDiff command to calculate the
difference between the two times ( answer to be in hours and mins ) although
DateDiff(¶î,,[Start_Time],[End_Time]) gives me the number of hours and
DateDiff(´ç,,[Start_Time],[End_Time]) gives me minuets how can I get the
correct hours and mins together in ideally one text box but two would be OK.

E.g. Start Time = 9:00 AM

End Time = 11:15 AM

Answer = 2h 15min

All I can get is ether 2h or 135min

Thanks for any help

Re: > gives me minuets < Are we invited to the dance? :-)>

Does this help?
= DateDiff("h",[Start],[End]) & " hours" & DateDiff("n",[Start],[End])
mod 60 & " minutes"
 
Back
Top