我正在使用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
答案 0 :(得分:2)
在Carbon对象中包裹日期:
// At top of file
use Carbon\Carbon;
$trackers = Tracker
::whereBetween('detect_at', [new Carbon($date1), new Carbon($date2)])
->where("serial", "uhu")
->get();
答案 1 :(得分:0)
$query->whereDate("created_at",'>=',$from)->whereDate("created_at",'<=',$today);