5

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
bytecode77
  • 14,163
  • 30
  • 110
  • 141
Hydral
  • 101
  • 1
  • 1
  • 10
  • 1
    seems relevant: http://stackoverflow.com/questions/24824624/laravel-q-where-between-dates I think your dates need to be date-objects – endofsource Aug 06 '15 at 20:22
  • What is the database column type for your `detect_at` column? Also, can you paste the SQL that is generated? – lowerends Aug 06 '15 at 20:41

2 Answers2

6

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();
Ben Claar
  • 3,285
  • 18
  • 33
0
$query->whereDate("created_at",'>=',$from)->whereDate("created_at",'<=',$today);
Michael
  • 46
  • 6