Siegmeyer Siegmeyer - 2 months ago 20x
PHP Question

Laravel: How to filter objects by date, where date is a UNIX timestamp?

I'm starting with Laravel (

) and I would like to filter table's rows by column which is a UNIX timestamp. Specifically I need
to be in some (date) range.

I imagine it would look something like:

$objs = DB::table('[table name]')->where('timestamp', [condition])->get();

I'm using
mongodb 2.2.3


What you're looking for is whereBetween.

$range = [timestamp1, timestamp2];
->whereBetween('timestamp', $range);

Also note that all methods on the query builder support Closure:

->whereBetween('timestamp', function($q){
    //some logic
    return [timestamp1, timestamp2];