Laravel/Eloquent 5 whereBetween 没有按预期工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31864679/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:08:20 来源:igfitidea点击:
Laravel/Eloquent 5 whereBetween not working as expected
提问by Hydral
I am using Laravel 5, and I would like get rows between two dates in my database (SQLite).
我正在使用 Laravel 5,我想在我的数据库 (SQLite) 中获取两个日期之间的行。
I am using this command:
我正在使用这个命令:
$trackers = Tracker::whereBetween('detect_at', [$date1, $date2])->where("serial", "uhu")->get();
But I get no response.
但我没有得到任何回应。
Entire request:
整个请求:
$date1 = "2015-07-13 03:53:38";
$date2 = "2015-07-13 03:58:36";
$trackers = Tracker::whereBetween('detect_at', [$date1, $date2])->where("serial", "uhu")->get();
Here is an example of one row in my database:
这是我的数据库中一行的示例:
id serial latitude longitude altitude accuracy detect_at created_at updated_at
728 uhu 48.0491 -1.74138 0 20 2015-07-13 03:54:38 2015-07-02 13:40:15 2015-07-02 13:40:15
采纳答案by Ben Claar
Wrap the dates in Carbon objects:
将日期包裹在 Carbon 对象中:
// At top of file
use Carbon\Carbon;
$trackers = Tracker
::whereBetween('detect_at', [new Carbon($date1), new Carbon($date2)])
->where("serial", "uhu")
->get();