Reputation: 219
Dim dtmStart As Date, dtmEnd As Date, dblDuration As Double
dtmStart = "1900/01/01 08:10:00"
dtmEnd = "1900/01/03 21:16:00"
dblDuration = DateDiff("hh:mm", dtmEnd, dtmStart)
'dblDuration = dtmEnd - dtmStart
MsgBox Format(dblDuration, "hh:mm")
How would I subtract two dates in a "yyyy/mm/dd hh:mm:ss" format? I tried both methods above and neither work
Upvotes: 4
Views: 24737
Reputation: 1
Well I am a simple Dane, and I like it simple, so I just did it like this:
Dim dtmStart As Date, dtmEnd As Date, dblDuration As Date
Start: 'STARTTIME
dtmStart = Time
Slut:
'SLUTTIDEN
dtmEnd = Time
dblDuration = dtmEnd - dtmStart
Debug.Print "Modul 1 Slut " & Time; " Run = "; dblDuration
Upvotes: 0
Reputation: 166181
Sub Test()
Dim dtmStart As Date, dtmEnd As Date, dblDuration As Double
dtmStart = "1900/01/01 08:10:00"
dtmEnd = "1900/01/03 21:16:00"
dblDuration = dtmEnd - dtmStart
MsgBox Application.Text(dblDuration, "[hh]:mm")
End Sub
Upvotes: 6