Converting Dates


String to Date

The CDATE function converts a String to a Date data type.

Dim sMyString As String 
Dim dtDate As Date
sMyString = "21/6/2023"
If (IsDate(sMyString) = True) Then
   dtDate = CDate(sMyString)
   Debug.Print dtDate
End If

Date to String

The CSTR function converts a Date to a String data type.
The DATESERIAL function returns a date given a year, month and day.

Dim sMyString As String 
Dim dtDate As Date
dtDate = DateSerial(2023,7,7)
sMyString = CStr(dtDate)
Debug.Print "My String is " + sMyString

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext