mysql中使用between的日期

hfyxw5xn  于 2021-06-20  发布在  Mysql
关注(0)|答案(2)|浏览(311)

我想用两个不同的日期显示记录。我试过用中间的

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

请帮我弄到这两个日期之间的记录。提前谢谢

n53p2ov0

n53p2ov01#

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

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
fxnxkyjh

fxnxkyjh2#

日期格式错误。如果 order_date 是mysql吗 DATE 那么格式应该是 2018-06-01

相关问题