Siegmeyer
Siegmeyer

Reputation: 4512

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

I'm starting with Laravel (4.2) and I would like to filter table's rows by column which is a UNIX timestamp. Specifically I need timestamp 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.

Upvotes: 1

Views: 1210

Answers (1)

Ohgodwhy
Ohgodwhy

Reputation: 50797

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];
});

Upvotes: 2

Related Questions