Mysql 利用str_to_date将字符串转换为日期 进行时间段查询

Mysql中STR_TO_DATE(str,format)方法将字符串str转换为format定义格式的日期类型

STR_TO_DATE("2019-01-20","%Y-%m-%d %H:%i:%s")

如果要做一个时间段的数字统计写法可以如下

select * from box where STR_TO_DATE(time,"yyyy/MM/dd") > STR_TO_DATE("2018/01/17","yyyy/MM/dd")  and time < STR_TO_DATE("2019/01/20","yyyy/MM/dd")

其中数据库中time字段类型为String类型
 

发布了4 篇原创文章 · 获赞 2 · 访问量 369

猜你喜欢

转载自blog.csdn.net/qq_33329834/article/details/104627819