Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 91
Default Solution: Calculating Time Elapsed Between Two Dates

Here are the components needed to calculate the days, hours, minutes,
and seconds between two dates...

Private Sub Difference()
Dim tStart As Date, tEnd As Date
Dim sTime As String, sDays As String
Dim sHours As String, sMin As String, sSec As String

tStart = Now - 0.12
tEnd = Now

sTime = DateDiff("s", tStart, tEnd)
sDays = ((((sTime / 60) / 60) / 24) Mod 60)
sHours = ((sTime / 60) / 60) Mod 24
sMin = (sTime / 60) Mod 60
sSec = sTime Mod 60
End Sub

tStart and tEnd are only in there to provide a couple of date values
to test the sub with. You can easily modify this to pass in a start
and end date like so:

Private Sub Difference(tStart As Date, tEnd As Date)

and then delete the three lines:

Dim tStart As Date, tEnd As Date
........
tStart = Now - 0.12
tEnd = Now

Thanks!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Solution: Calculating Time Elapsed Between Two Dates

you have a problem he

sDays = ((((sTime / 60) / 60) / 24) Mod 60)


Unless you want that to mean the number of days in the remainder after
dividing the number of days by 60; but not sure that is a standard of any
sort.
--
Regards,
Tom Ogilvy


" wrote:

Here are the components needed to calculate the days, hours, minutes,
and seconds between two dates...

Private Sub Difference()
Dim tStart As Date, tEnd As Date
Dim sTime As String, sDays As String
Dim sHours As String, sMin As String, sSec As String

tStart = Now - 0.12
tEnd = Now

sTime = DateDiff("s", tStart, tEnd)
sDays = ((((sTime / 60) / 60) / 24) Mod 60)
sHours = ((sTime / 60) / 60) Mod 24
sMin = (sTime / 60) Mod 60
sSec = sTime Mod 60
End Sub

tStart and tEnd are only in there to provide a couple of date values
to test the sub with. You can easily modify this to pass in a start
and end date like so:

Private Sub Difference(tStart As Date, tEnd As Date)

and then delete the three lines:

Dim tStart As Date, tEnd As Date
........
tStart = Now - 0.12
tEnd = Now

Thanks!


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculating total elapsed minutes between two dates Doug in Freight Excel Discussion (Misc queries) 2 June 17th 09 06:48 PM
Calculating Elapsed Time Rosemary Excel Worksheet Functions 2 March 23rd 09 03:23 PM
Calculating elapsed time tele2002 Excel Discussion (Misc queries) 2 December 22nd 05 05:47 PM
Calculating Time elapsed bhomer Excel Worksheet Functions 1 November 21st 05 01:16 PM
Calculating elapsed time andoh Excel Worksheet Functions 5 November 17th 05 11:31 AM


All times are GMT +1. The time now is 04:08 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"