Jump to content

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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...