Rob*_*b M 0 coldfusion coldfusion-9
我正在使用cfscript语法创建一个查询,我有两个日期查询参数.我第一次使用时创建了日期字符串
queryservice.addParam(
name="last_update",
value="createODBCDate(now())",
cfsqltype="cf_sql_date");
Run Code Online (Sandbox Code Playgroud)
我认为这可以类似于:
<cfqueryparam value="#createODBCDate(now())#" cfsqltype="cf_sql_date">
Run Code Online (Sandbox Code Playgroud)
所以,当我运行查询时,我得到:
The cause of this output exception was that: coldfusion.runtime.Cast$DateStringConversionException: The value createODBCDate(now()) cannot be converted to a date.
Run Code Online (Sandbox Code Playgroud)
精细.所以我创建了一个变量,
var currentDate = createODBCDate(now());
Run Code Online (Sandbox Code Playgroud)
把它添加到
queryservice.addParam(
name="last_update",
value="createODBCDate(now())",
cfsqltype="cf_sql_date");
Run Code Online (Sandbox Code Playgroud)
得到了
The cause of this output exception was that: coldfusion.runtime.Cast$DateStringConversionException: The value currentDate cannot be converted to a date.
Run Code Online (Sandbox Code Playgroud)
当我使用标准<cfquery ...语法创建查询时,它工作正常.
所以,我假设我做错了什么,但我不能为我的生活找出那是什么.
顺便说一句,这是我第一次尝试使用<cfscript>语法创建查询.
value="createODBCDate(now())"
你忘记了函数周围的#符号.没有这些,它只是一个字符串.因此,永远不会调用该函数,并最终将文字字符"createODBCDate(now())"作为日期传递value.
更新:
另外,cf_sql_date自动删除任何时间部分.因此,虽然使用createODBCDate不会伤害任何东西,但它是多余的.你可以简单地写:
queryservice.addParam(
name="last_update",
value="#now()#",
cfsqltype="cf_sql_date");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
923 次 |
| 最近记录: |