Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

To calculate the time difference between two days

  Asked By: Kenneth    Date: Feb 20    Category: MS Office    Views: 864
  

I want to find the difference in hours between two days.
Like difference between 6/25/2007 12:30:00 and 6:28/2007 10:45:00....
I want to get the result in HH:MM format.

Share: 

 

4 Answers Found

 
Answer #1    Answered By: Luki Fischer     Answered On: Feb 20

Dim intDiff as integer, strDiff as String

intDiff = DateDiff("n", date1, date2)

strDiff = CStr(Int(intDiff/60)) & ":" & CStr(intDiff mod 60)

Debug.Print strDiff

 
Answer #2    Answered By: Dennis Hayes     Answered On: Feb 20

This program returns the number of days  between two dates. I need the hours
between these two days.
Like, the number of hours between

06/25/2006 6:20:00 and
06/28/2006 13:30:00

is 79:10 hours.

I want a program to calculate  the number of hours and minutes(hh:mm
format)between two days.
Please help.

 
Answer #3    Answered By: Canan Kaya     Answered On: Feb 20

I believe you are wrong, and I assume you have not tried the code. I wrote
it into a function for you, and changed the integer to a long to handle
larger values.



Public Function HoursDiff(date1, date2) As String

Dim Diff As Long, strDiff As String

lngDiff = DateDiff("n", date1, date2)

strDiff = CStr(Int(lngDiff / 60)) & ":" & CStr(lngDiff Mod 60)

HoursDiff = strDiff

End Function



In my immediate window, I got:

?hoursdiff(#06/25/2005 6:20:00#, # 06/28/2006 13:30:00#)

8839:10



The key is the first argument to the DateDiff function -- the "n" computes
the number of minutes between two dates. You could check the docs on
DateDiff.



I believe I'm handing it to you on a silver platter. You might want to test
it.

 
Answer #4    Answered By: Steve Boyd     Answered On: Feb 20

I am sorry. It was my fault. I did test the code and it worked good.
Thanks for your help.

 
Didn't find what you were looking for? Find more on To calculate the time difference between two days Or get search suggestion and latest updates.




Tagged: