Calculate a difference in dates

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)
 
S

StCyrM

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
 

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