gpt4 book ai didi

php - Laravel - 使用 eloquent 在开始日期和结束日期之间选择行

转载 作者:行者123 更新时间:2023-12-04 20:19:37 26 4
gpt4 key购买 nike

我想将此查询转换为 Laravel eloquent,

select * from schedule where (now() between start_date and end_date);

我尝试使用 whereBetween,但出现了一些错误。
$schedule = Schedule::whereBetween(Carbon::now(), ['start_date', 'end_date'])->get();

错误看起来像这样

QueryException in Connection.php line 647: SQLSTATE[42S22]: Column not found: 1054 Unknown column '2017-06-01 06:17:30' in 'where clause' (SQL: select * from schedule where 2017-06-01 06:17:30 between start_date and end_date)



任何的想法?

最佳答案

$from = $request->from;
$to = $request->to;
$title="Sales From: ".$from." To: ".$to;
$sales = Sale::whereBetween('created_at', [$from.' 00:00:00',$to.' 23:59:59'])->get();

关于php - Laravel - 使用 eloquent 在开始日期和结束日期之间选择行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44300126/

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