mysql date in_SELECT date in Mysql Returning wrong data

I'm trying to generate a report, but It's returning incorret data. I'm trying to search informations between two different dates.

$data1 = '21/02/2019 03:46';

$data2 = '16/08/2019 03:46';

$data1 = DateTime::createFromFormat('d/m/Y H:i', $data1)->format('Y-m-d');

$data2 = DateTime::createFromFormat('d/m/Y H:i', $data2)->format('Y-m-d');

echo $data1;

$sql = "

SELECT p.pedido_id

, p.pedido_status

, STR_TO_DATE(p.pedido_data,'%d/%m/%Y') as pedido_data

, l.lista_pedido

, l.lista_item as item_id

, l.lista_title as item_title

, SUM(l.lista_qtde) as total

FROM pedido p

JOIN lista l

ON lista_pedido = pedido_id

WHERE pedido_status = 3

AND (pedido_data >= $data1 AND pedido_data <= $data2)

GROUP by item_id;

";

$query = mysqli_query($conn,$sql);

When it appears the result, it brings results from other dates either.

This is the table of Results:

253 Fio de Malha - Marfim 2018-12-08

254 Fio de Malha - Areia 2018-12-07

257 Kit Clutch alça corrente Pérola 2019-02-18

258 Alça corrente Acrílica - Branca 2019-02-18

259 Alça corrente Acrílica - Preta 2019-02-18

261 Alça corrente Acrílica - Goiaba 2019-02-19

262 Alça corrente Acrílica - Vermelha 2019-02-24

263 Alça corrente Acrílica - Marrom 2019-02-26

I'd really appreciate if someone could help me to solve this issue. I don't know where I'm going wrong.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值