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)
End Sub

執行函式後,將生成以下輸出。

The Value of a : 1/01/2020
The Value of b : 31/12/2050 
vba_date_time.htm
Advertisement
© . All rights reserved.