HQL查询从日期时间数据中过滤日期

时间:2011-05-29 05:27:53

标签: hql datetime-format

我想将日期时间格式转换为HQL计数中的字符串格式。 例如,我在多个员工的每个月的每一天都有多余的出勤数据,我需要计算并获得一天的不同数据。

select Count(distinct att.AttDate) from AttendanceTable att where att.AttDate between '" + startDate.Date + "' and '" + endDate.Date + "'

但是此查询由于时间值而计算每个日期时间数据。所以我需要将datetime转换为字符串。

1 个答案:

答案 0 :(得分:1)

HQL仅允许certain set of functions

尝试

select count(distinct (
    day(att.AttDate) + 
    31 * month(att.AttDate) + 
    366 * year(att.AttDate) ))

您可以尝试str()cast(),但结果不会在不同的数据库中保持一致。

相关问题