【问题标题】:VBA subtract date and timesVBA减去日期和时间
【发布时间】:2012-06-30 11:54:48
【问题描述】:
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”格式减去两个日期?上面两种方法我都试过了,都不管用

【问题讨论】:

    标签: excel vba date


    【解决方案1】:
    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
    

    【讨论】:

    • 谢谢!小时左右的方括号是我需要的:|
    • @JFC - 即使 cmets 也有限制
    【解决方案2】:

    嗯,我是一个简单的丹麦人,我喜欢简单,所以我就这样做了:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-14
      相关资源
      最近更新 更多