View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
[email protected] crferguson@gmail.com is offline
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!