逐梦论坛's Archiver

shillan 发表于 2018-8-22 16:51

SQL语句模糊查询日期时间的方法

模糊查询有以下三种方法:
1.Convert转成String,再用Like查询。适用于任何数据类型:
select * from table where convert(varchar,date,120) like '2018-08-22%'
2.Between。适用于String外的类型:
select * from table where time between '2018-8-22 0:00:00' and '2018-8-22 24:59:59'
3 datediff()函数,为date类型定制的比较实用快捷的方法:
select * from table where datediff(day,time,'2018-8-22')=0

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.