CDate function
Returns an expression that has been converted to a Variantof the Date subtype.
CDate(date)
The date parameter is any valid datetime expression.
Description
The IsDate function is used to determine whether date can be converted to a date or time. CDate recognizes date and time literals, as well as some numbers within an acceptable date range. When you convert a number to a date, the integer portion of the number is converted to a date, and the fractional portion is converted to the time calculated from midnight.
CDate The date format according to the locale settings of the system. If the format of the data cannot be identified by the date setting, the correct order of year, month, and day cannot be judged. In addition, if the long date format contains a string that represents the day of the week, it cannot be recognized.
The following example uses the CDate function to convert a string to a date type. It is generally not recommended to use hardware decoding dates and times as strings (as shown in the following example). Use time and date literals (such as #10/19/1962#, #4:45:23 pm#).
mydate = "October, 1962
"
defines the date. myshortdate = CDate ( mydate )
'
to the date data type. mytime = "4:35:47 PM"
'
defines the time. myshorttime = CDate ( mytime )
'
to the date data type.