Reputation: 111
I am using Laravel 5, and I would like get rows between two dates in my database (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
Upvotes: 6
Views: 14519
Reputation: 44
$query->whereDate("created_at",'>=',$from)->whereDate("created_at",'<=',$today);
Upvotes: 0
Reputation: 3415
Wrap the dates in Carbon objects:
// At top of file
use Carbon\Carbon;
$trackers = Tracker
::whereBetween('detect_at', [new Carbon($date1), new Carbon($date2)])
->where("serial", "uhu")
->get();
Upvotes: 6