VBScript CDateFunction
Complete VBScript Reference
The CDate function converts a valid date and time expression to a Date type, and returns the result. p>
Tip:Use the IsDate function to determine whether a date can be converted to a date or time.
Note:The IsDate function uses local settings to detect whether a string can be converted to a date (in all languages, "January" is not a month).
Syntax
CDate(date)
| Parameter | Description |
|---|---|
| date | Required. Any valid date expression (such as Date() or Now()). |
Examples
Example 1
How to convert a string to a date:
<script type="text/vbscript">
d=CDate("April 22, 2010")
</script>
d=CDate("April 22, 2010")
</script>
Try it Yourself »
Example 2
How to convert numbers with separators to a date:
<script type="text/vbscript">
d=CDate(#4/22/10#)
</script>
d=CDate(#4/22/10#)
</script>
Try it Yourself »
Example 3
How to use CDATE to convert a string to a time object:
<script type="text/vbscript">
d=CDate("3:18:40 AM")
</script>
d=CDate("3:18:40 AM")
</script>
Try it Yourself »
Complete VBScript Reference Other Extensions