1

我有以下方法:

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 时我的日期应该采用什么格式?

非常感谢

4

2 回答 2

2

简单版:

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

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

因此,可能更准确的方法是:

ormExecuteQuery("FROM Employment WHERE publishdate <= :today and expirydate >= :today ORDER BY tstamp desc", {today = DateFormat(Now(), 'yyyy-mm-dd')});
于 2012-10-15T11:54:57.257 回答
1

尝试

DateFormat(Now(), "yyyy-mm-dd")
于 2012-10-15T10:57:25.420 回答