• Status: Solved
• Priority: Medium
• Security: Public
• Views: 3456

# Convert date difference to second, minutes and hours

I need to calculate the time between two dates into hours, minutes and seconds between the two times.  Say, a task starts at 6/13/2008  3:30:51 PM and end at   6/13/2008 7:10:28 PM, I need to the total time in hours, minutes and second.  I started with the DateDiff using seconds as the unit, but simply dividing by 60 would get total minutes, but the remainder for seconds is in tenths, rather than the seconds I want.  How do I transalate into a resul of say 3 hours, 25 minutes and 15 seconds?
0
Sandra Smith
• 2
• 2
1 Solution

Commented:
place this codes in a module

Function ElapsedTime (Interval)
Dim x
x = Int(CSng(Interval * 24 * 3600)) & " Seconds"
Debug.Print x
x = Int(CSng(Interval * 24 * 60)) & ":" & Format(Interval, "ss") _
& " Minutes:Seconds"
Debug.Print x
x = Int(CSng(Interval * 24)) & ":" & Format(Interval, "nn:ss") _
& " Hours:Minutes:Seconds"
Debug.Print x
x = Int(CSng(Interval)) & " days " & Format(Interval, "hh") _
& " Hours " & Format(Interval, "nn") & " Minutes " & _
Format(Interval, "ss") & " Seconds"
Debug.Print x

End Function

to use, pass the  two values to the function like this

ElapsedTime(#6/13/2008 7:10:28 PM#-#6/13/2008  3:30:51 PM#)

0

Commented:
place this codes in a module

Function ElapsedTime (Interval)
Dim x
x = Int(CSng(Interval * 24 * 3600)) & " Seconds"
' Debug.Print x
x = Int(CSng(Interval * 24 * 60)) & ":" & Format(Interval, "ss") _
& " Minutes:Seconds"
'  Debug.Print x
x = Int(CSng(Interval * 24)) & ":" & Format(Interval, "nn:ss") _
& " Hours:Minutes:Seconds"
'  Debug.Print x
x = Int(CSng(Interval)) & " days " & Format(Interval, "hh") _
& " Hours " & Format(Interval, "nn") & " Minutes " & _
Format(Interval, "ss") & " Seconds"
'  Debug.Print x

ElapsedTime=x

End Function

to use, pass the  two values to the function like this

ElapsedTime(#6/13/2008 7:10:28 PM#-#6/13/2008  3:30:51 PM#)

0

RetiredAuthor Commented:
Be right back, I am going to try that
0

RetiredAuthor Commented:
Thanks Cap, it works.  Appreciate it/
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.