Solved

Convert date difference to second, minutes and hours

Posted on 2008-06-14
4
3,352 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

732 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