VBScript CDate Function
Definition and Usage
The CDate function can convert a valid date and time expression to the Date type and return the result.
Tip:Use the IsDate function to determine whether the date can be converted to a date or time.
Note:The IsDate function uses the local settings to determine whether a string can be converted to a date.
Syntax
CDate(date)
Parameter | Description |
---|---|
date | Required. Any valid date expression (such as Date() or Now()). |
Instance
Example 1
d="April 22, 2001" if IsDate(d) then document.write(CDate(d)) end if
Output:
2/22/01
Example 2
d=#2/22/01# if IsDate(d) then document.write(CDate(d)) end if
Output:
2/22/01
Example 3
d="3:18:40 AM" if IsDate(d) then document.write(CDate(d)) end if
Output:
3:18:40 AM