在MYSQL中使用BETWEEN的日期

时间:2018-07-30 06:30:01

标签: mysql date between

我想使用两个不同的日期显示记录。我尝试使用之间

select * from billing where select_client = '2' and order_date BETWEEN '01/06/2018' and '30/06/2018' order by id ASC 

它也返回7月的月份记录。我尝试使用> =和<=。该查询还会返回相同的记录。

select * from billing where select_client = '2' and order_date >= '01/06/2018' and order_date <= '30/06/2018' order by id ASC 

请帮助我仅获取两个日期之间的记录。预先感谢enter image description here

2 个答案:

答案 0 :(得分:1)

您必须将字符串转换为日期以进行比较:

select * from billing where select_client = '2' and STR_TO_DATE(order_date, '%d/%m/%Y') BETWEEN STR_TO_DATE('01/06/2018','%d/%m/%Y') and STR_TO_DATE('30/06/2018','%d/%m/%Y') order by id ASC 

答案 1 :(得分:0)

日期格式错误。如果order_date是mysql DATE,则格式应为2018-06-01