我正在使用 Laravel 5,我想在我的数据库 (SQLite) 中获取两个日期之间的行。
我正在使用这个命令:
$trackers = Tracker::whereBetween('detect_at', [$date1, $date2])->where("serial", "uhu")->get();
但我没有得到任何回应。
整个请求:
$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();
这是我的数据库中一行的示例:
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
最佳答案
将日期包裹在 Carbon 对象中:
// At top of file
use Carbon\Carbon;
$trackers = Tracker
::whereBetween('detect_at', [new Carbon($date1), new Carbon($date2)])
->where("serial", "uhu")
->get();
关于php - Laravel/Eloquent 5 whereBetween 没有按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31864679/