I am creating a query using cfscript syntax, and I have two query parameters that are dates. I created the date string the first time using
queryservice.addParam(
name="last_update",
value="createODBCDate(now())",
cfsqltype="cf_sql_date");
I would assume this would an analogue to:
<cfqueryparam value="#createODBCDate(now())#" cfsqltype="cf_sql_date">
So, when I run the query, I’m getting:
The cause of this output exception was that: coldfusion.runtime.Cast$DateStringConversionException: The value createODBCDate(now()) cannot be converted to a date.
Fine. So I created a variable,
var currentDate = createODBCDate(now());
added it to
queryservice.addParam(
name="last_update",
value="createODBCDate(now())",
cfsqltype="cf_sql_date");
and got
The cause of this output exception was that: coldfusion.runtime.Cast$DateStringConversionException: The value currentDate cannot be converted to a date.
When I created the query using the standard <cfquery ... syntax it worked fine.
So, I’m assuming that I am doing something wrong, but I can’t for the life of me figure out what that is.
By the way, this is really my first time trying to create a query using the <cfscript> syntax.
You forgot the # signs around the function. Without those, it is just a string. So the function is never invoked and you end up passing in the literal characters “createODBCDate(now())” as the date
value.Update:
As an aside,
cf_sql_dateautomatically removes any time portion. So while usingcreateODBCDatewill not hurt anything, it is redundant. You could simply write: