Friday, August 28, 2009

ASP - Convert String to Date

ASP - Convert String to Date

ASP makes converting string to date very easy. We’re going to use the CDate ASP/VBScript function in our ASP code to convert a string to a date value.

ASP CDate function has the following syntax:

CDate (Date)

ASP CDate function has 1 string argument, which is the string to be converted to date.
The CDate function converts any valid date/time string expression to Date variant subtype.

Consider the following use of ASP CDate function, to convert sDate string to date:

<%
sDate = "January 13, 1970"
Response.Write CDate(sDate)
%>

The result displayed in your browser will be:

1/13/70

No comments:

Post a Comment