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")

如何以“yyyy/mm/dd hh:mm:ss”格式减去两个日期?我尝试了上面的两种方法,但都不起作用

最佳答案

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

关于excel - VBA 减去日期和时间,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11253506/

10-09 05:21