CDate Conversion Problem

Posted on 2004-11-05
Last Modified: 2012-06-21
if Request.Form("ret") = "" then
                         dtret = "8/9/2004"
                      end if
                      if Request.Form("ret2") = "" then
                         dtret = "5/31/2005"
                      end if

                      strSQLEF = "Calendar.dbo.kwsSP_GetEventsFound '" & CDate(dtret) & "', '" & CDate(dtret2) & "', '"  & "%" & strevent & "%" & "', '"  & strevent & "%"  & "', '"


Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'CDate'
/htdocs/calendar/events_found.asp, line 271
Question by:kwcowboy1226
    LVL 48

    Expert Comment

    LVL 44

    Accepted Solution

    it appears that you are using SQL Server as the database?  in which case, you code should look like this:

    strSQLEF = "Calendar.dbo.kwsSP_GetEventsFound '" & dtret & "', '" & dtret2 & "', '"  & "%" & strevent & "%" & "', '"  & strevent & "%"  & "', '"

    SQL Server does NOT recognize Date type values from VBScript, as DateTime values in SQL Server.

    a VBScript Date type value is actually being passed as a NUMBER with a decimal point, ehich is not a datetime value in SQL Server.

    LVL 55

    Expert Comment

    by:Jaime Olivares
    You don't need CDate since both dret and dret2 are strings.
    The concatenating operator & needs string, so will be enough:
    strSQLEF = "Calendar.dbo.kwsSP_GetEventsFound '" & dtret & "', '" & dtret2 & "', '"  & "%" & strevent & "%" & "', '"  & strevent & "%"  & "', '"

    LVL 1

    Expert Comment

    you could put CDate(dtret)into a new var type string and then use the new string var(date previously validated with cdate) into the sql sentence concatenated with '"& newvar &"'

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Title # Comments Views Activity
    format the code in java 6 60
    How to silent print from safari browser 6 97
    linearIn  challenge 23 54
    sumDigits  challenge 7 39
    I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now