这个函数将有效的日期和时间表达式转换为类型日期。
语法
cdate(date)
示例
添加一个模块,并添加以下示例代码 -
Private Sub Constant_demo_Click()
Dim a As Variant
Dim b As Variant
a = CDate("Jan 01 2020")
MsgBox ("The Value of a : " & a)
b = CDate("31 Dec 2050")
MsgBox ("The Value of b : " & b)
c = CDate("2018-12-20")
MsgBox ("The Value of c : " & c)
End Sub
执行上面示例代码,得到以下结果 -
The Value of a : 2020/01/01
The Value of b : 2050/12/31
The Value of c : 2018/12/20