• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1287
  • Last Modified:

CDate Conversion Problem

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:

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'CDate'
/htdocs/calendar/events_found.asp, line 271
0
kwcowboy1226
Asked:
kwcowboy1226
1 Solution
 
Arthur_WoodCommented:
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.

AW
0
 
Jaime OlivaresCommented:
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 & "%"  & "', '"

BR,
Jaime.
0
 
limongCommented:
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 &"'
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now