Solved

Convert date difference to second, minutes and hours

Posted on 2008-06-14
4
3,332 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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) 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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Access on Mouse move 5 33
VBA SQL statement - 2 "OR"s and 1 "And" 4 27
Part 2 to aggregate query solved qtn 12 29
Switch 5 16
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

770 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