CF ORM ormExecuteQuery(),日期应该是什么格式?

时间:2012-10-15 04:17:54

标签: hibernate coldfusion

我有以下方法:

public function listPublished(){
        var today = createODBCDate(now());
        return ormExecuteQuery("FROM Employment WHERE publishdate <= #today# and expirydate >= #today# ORDER BY tstamp desc");
}

当我运行它时,我收到以下错误:

org.hibernate.QueryException: unexpected char: '{' [FROM EmploymentFindSonographer WHERE publishdate <= {d '2012-10-15'} and expirydate >= {d '2012-10-15'} ORDER BY tstamp desc]

我的猜测是HQL需要ODBC日期以外的格式吗?我也试过传递一个标准的CF日期,但同样的错误。

有人能告诉我将HQL传递给ormExecuteQuery时我的日期应该是什么格式吗?

非常感谢

2 个答案:

答案 0 :(得分:2)

Simpe版本:

ormExecuteQuery("FROM Employment WHERE publishdate <= :today and expirydate >= :today ORDER BY tstamp desc", {today = Now()});

可能的问题是,如果publishDate和expiryDate保持日期+时间,Now()会输出秒,这可能会给你意想不到的结果。

所以,可能更准确的方法是:

ormExecuteQuery("FROM Employment WHERE publishdate <= :today and expirydate >= :today ORDER BY tstamp desc", {today = DateFormat(Now(), 'yyyy-mm-dd')});

答案 1 :(得分:1)

尝试

DateFormat(Now(), "yyyy-mm-dd")