MySQL模糊查询日期时间的方法

今天在写一个SSM项目时,其中需要到用模糊查询日期,之前没有用过 ,在网上翻阅一些资料查找到一些方法,特来跟大家分享下:

Mysql模糊查询有以下三种方法:


1.Convert转成String,在用Like查询。
select * from table1 where convert(varchar,date,120) like '2006-04-01%'
第一种方法应该适用与任何数据类型;


2.Betwee
select * from table1 where time between '2018-08-01 0:00:00' and '2018-08-01 24:59:59'";
第二种方法适用String外的类型;


3 datediff()函数
select * from table1 where datediff(create_time,'2018-08-01')=

第三种方法则是为date类型定制的比较实用快捷的方法。


 

猜你喜欢

转载自blog.csdn.net/baidu_41660182/article/details/81365448
今日推荐