Solved

Convert date difference to second, minutes and hours

Posted on 2008-06-14
4
3,309 Views
Last Modified: 2008-06-14
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
Comment
Question by:ssmith94015
  • 2
  • 2
4 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 21785951
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
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 21785958
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
 

Author Comment

by:ssmith94015
ID: 21785956
Be right back, I am going to try that
0
 

Author Comment

by:ssmith94015
ID: 21785999
Thanks Cap, it works.  Appreciate it/
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now