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, 2014")
 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/2014
The Value of b : 3/11/2014
The Value of c : 3:11:14 AM

Explanation

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

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