ventaquil
ventaquil

Reputation: 2848

Date in MySQL Laravel ORM

I store my dates in timestamp type (and I see in PHPMyAdmin for simple 2015-04-14 00:00:00). Is it stupid? Better way is set to int type and save UNIX time?

How can I do query

select * from `values` where `time` < $mytimeinunix

because Model::all()->where('time','<',$mytimeinunix) is not working.

Regards

Upvotes: 2

Views: 135

Answers (1)

Limon Monte
Limon Monte

Reputation: 54419

You're looking for UNIX_TIMESTAMP:

Model::where(DB::raw('UNIX_TIMESTAMP(time)'), '<', $mytimeinunix)->get();

Upvotes: 3

Related Questions