【发布时间】:2021-07-02 10:03:56
【问题描述】:
我正在尝试以下非常简单的 VBA 代码来转换为日期时间
Sub datetimedifffference()
Dim d As String
Dim sd As Date
d = "2021-04-06T12:56:16+0000"
sd = Format(CDate(d), "mm-dd-yyyy hh:mm:ss")
Debug.Print sd
End Sub
但是它给出了类型不匹配的错误 任何帮助将不胜感激
我在下面再次尝试,但时间差是减少而不是增加
Sub datetimedifffference()
Dim d As String
Dim sd As Long
d = "2021-04-06T12:56:16+0000"
sd = DateDiff("n", Now, Format(convertStringtoDate(d))
Debug.Print sd
End Sub
Function convertStringtoDate(stringdate As String) As String
Dim strings() As String
strings = Split(stringdate, "T")
convertStringtoDate = strings(0) & " " & Left(strings(1), 8)
'Debug.Print convertStringtoDate
End Function
【问题讨论】:
-
试试 IsDate 看看 d 是否可以转换成日期。
标签: vba date time timestamp timestampdiff