如何实现hql语句对时间进行时间的模糊查询

2026年09月24日 06:45
有1个网友回答
网友(1):

模糊查询有以下三种方法:
1.Convert转成String,在用Like查询。
select * from table1 where convert(varchar,date,120) like '2006-04-01%'

2.Between
select * from table1 where time between '2006-4-1 0:00:00' and '2006-4-1 24:59:59'";

3 datediff()函数
select * from table1 where datediff(day,time,'2006-4-1')=0

第一种方法应该适用与任何数据类型;
第二种方法适用String外的类型;
第三种方法则是为date类型定制的比较实用快捷的方法。