mysql 根据时间范围查询

时间格式为

第一种写法:

select * from test where create_time between '2019-03-05 13:04:07' and '2019-03-08 13:04:07';

第二种写法:


select * from test where create_time >= '2019-03-05 13:04:07' and date <= '2019-03-08 13:04:07';

如果传入的格式是YYYY-MM-DD 的 没有带时分秒,按照上面两种写法会差不全。

解决办法:

一、改变传入格式。改为 YYYY-MM-DD hh:mm:ss 就可以使用上面两种写法

二、你用mysql的函数date_format

select * from test where date_format(create_time,'%Y-%m-%d') between '2019-03-05' and '2019-03-08';

猜你喜欢

转载自blog.csdn.net/qq_36189144/article/details/88350390