VBA CDate()函數

這個函數將有效的日期和時間表達式轉換為類型日期。

語法

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

上一篇: VBA日期時間函數 下一篇: VBA數組