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

String to Long

Using CDbl will not round. Using CInt or CLng will round according to time.

Dim sMyString As String 
Dim dtDate As Date
Dim sMyDouble As Double
sMyString = "01-Jul-2026"
sMyDouble = CDbl(CDate(sMyString))
Debug.Print "My serial number is " & sMyDouble

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