gpt4 book ai didi

php - 从 Laravel 中的一系列日期获取行

转载 作者:行者123 更新时间:2023-11-29 10:42:27 25 4
gpt4 key购买 nike

我正在尝试通过应用两个日期范围从数据库中获取行。开始和结束

下面是测试数据。

Collection {#258 ▼
#items: array:4 [▼
0 => Customer_history {#237 ▶}
1 => Customer_history {#260 ▶}
2 => Customer_history {#261 ▶}
3 => Customer_history {#262 ▼
#attributes: array:12 [▼
"ch_id" => 1
"customer_id" => 1
"invoice_id" => 12
"created_at" => "2017-07-17 22:57:55"
"updated_at" => "2017-07-17 22:57:55"
"branch_id" => 1
"salesman_id" => 1
"remarks" => ""
"invoice_no" => ""
"advance" => ""
"is_delivered" => 1
"is_paid" => 1
]
}
]
}

如您所见,有两个日期为 2017-07-17 现在,当我应用创建了两个日期的查询时

$from = date_create("2017-07-17");
$till = date_create("2017-07-17");

$customer_histories = Customer_history::leftJoin('invoices AS i', 'i.invoice_id', 'customer_histories.invoice_id')
->where('is_paid','=',1)
->whereBetween('customer_histories.created_at', [$from,$till])
->get();

这不会返回任何行,它应该返回 1 行!我想我错过了一些东西。谁能帮我找出应该省略或修改哪些内容才能使其发挥作用?

最佳答案

试试这个。删除这些行

$from = date_create("2017-07-17");
$till = date_create("2017-07-17");

并输入此查询

$customer_histories = Customer_history::leftJoin('invoices AS i', 'i.invoice_id', 'customer_histories.invoice_id')
->where('is_paid','=',1)
->whereRaw('DATE_FORMAT(customer_histories.created_at, "%Y-%m-%d") BETWEEN ? AND ?', [ $from, $till])
->get();

关于php - 从 Laravel 中的一系列日期获取行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45224551/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com