VBScript CDate function

VBScript CDate() function

CDate() function converts a valid date and time expression to type date.

Syntax :

CDate(date)

Example

<!DOCTYPE html>
<html>
<body>
<script language="vbscript" type="text/vbscript">
 a = CDate("March 11, 2025")
 document.write("The Value of a : " & a)
 document.write("<br />")
 b = CDate(#3/11/14#)
 document.write("The Value of b : " & b)
 document.write("<br />")
 c = CDate("3:11:14 AM")
 document.write("The Value of c : " & c)
</script>
</body>
</html>

Output :

The Value of a : 3/11/2024
The Value of b : 3/11/2024
The Value of c : 3:11:14 AM

Explanation

In the above example we have performed operations on 3 different inputs.

ExampleExplanation
Example 1String of date can be converted to a type Date using CDate() function
Example 2In the example we have used date string with separator as a parameter to CDate() function
Example 3time string is passed as parameter to CDate() function. CDate() converts a string to a time object