24 | 03 | 2017

Subtract Dates

Calculate the time difference between two dates.

Public Function CalculateTimeDiference(ByVal Date1, ByVal Date2) As Date
  
'*************************************
'**** Code from VisibleVisual.com ****
'*************************************

     Dim sec1, sec2, secOut, minsOut, hoursOut
   'Convert Time to seconds
     sec1 = (Hour(Date1) * 3600) + (Minute(Date1) * 60) + Second(Date1)
    sec2 = (Hour(Date2) * 3600) + (Minute(Date2) * 60) + Second(Date2)
     'Subtract one from the other
    secOut = sec1 - sec2 ' or Add together to sum two times
     'Calc hours
     hoursOut = Int(secOut / 3600)
    secOut = secOut - (hoursOut * 3600)
     'Calc minutes
     minsOut = Int(secOut / 60)
     secOut = secOut - (minsOut * 60)
 'Convert back to HH:MM:SS
 TimeDiff = TimeValue(Format(hoursOut, "00") + ":" + Format(minsOut, "00") + ":" + Format(secOut, "00"))
   
End Function
Login

Sign up now and upload your code to the website.

Help us to continue.....
Statistics
Articles View Hits
2206753
Latest Articles