VBA - Fonction CDate

La fonction convertit une expression de date et d'heure valide en type date.

Syntaxe

cdate(date)

Exemple

Ajoutez un bouton et ajoutez la fonction suivante.

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

Lorsque vous exécutez la fonction, elle produit la sortie suivante.

The Value of a : 1/01/2020
The Value of b : 31/12/2050