Calculate a difference in dates

  • Thread starter Thread starter tony
  • Start date Start date
T

tony

Hi

Not sure if this the right group but here goes

I have a form(or report ) displaying 2 dates in the format dd/mm/yy hh:nn.

Can anybody please help
I am trying to have another field display the difference between the two
(displayed in days hours minutes.)

Any help greatly appreciated

Tony L

(e-mail address removed)
 
Hi Tony

This will return a string of Days, Hours and Minutes.




Public Function ShowDateDiff(dt1 As Date, dt2 As Date) As String
Dim lngDays As Long
Dim lngHours As Long
Dim lngMinutes As Long

lngMinutes = DateDiff("n", dt2, dt1)

lngDays = lngMinutes / 1440
lngHours = (lngMinutes - (lngDays * 1440)) / 60
lngMinutes = lngMinutes - (lngDays * 1440) - (lngHours * 60)

ShowDateDiff = lngDays & " days " & lngHours & " hours " & lngMinutes & "
minutes"

End Function
 
Back
Top