Jump to content

CDate Error Classic ASP


philipjbailey
 Share

Recommended Posts

  • [*]

Hi I have a work around for this one but for other reasons I want to work with numeric dates e.g. 01/02/2010 rather than string dates e.g. 1 February 2010.

 

IF I use the Visual basic adate = CDate(#1/2/2010#) all works perfectly and adate would have the value 01/02/2010 in date format.

Here is where the problem starts.

The date is captured from an ASP Form using form dropdowns for day and month so the code looks like this

Dim xday, xmonth, xyear, adate

xday = Request.Form("xday")

xmonth = Request.Form("xmonth")

xyear = Request.Form("xyear")

adate = CDate("#" & aday & "/" & amoth & "/" & ayear & "#")

Result is a Type Mismatch

The problem is obvious

CDate("#" & aday & "/" & amonth & "/" & ayear & "#") Is effectively equivalent to CDate("#01/02/2010#") (a String Value) Causing the Error as the required value #01/02/2010# is not a string value.

Question: How do I convert the Concatenated String "#01/02/2010#" into the correct format for CDate to work correctly so that the value adate can be inserted into a Database Date Field?

The work Around uses the Month Names I.e February and code CDate(aday & " " & amonth & " " & ayear) Which does work but requires the extra coding later on to covert amonth to a numeric month number.

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...