Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Kenneth Bennett   on Feb 20 In MS Office Category.

  
Question Answered By: Canan Kaya   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.

Share: 

 

This Question has 3 more answer(s). View Complete Question Thread

 
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: