php - Eloquent select from database, get results newer than a given unix timestamp -
i select rows database newer specified unix timestamp specified in parameters.
the column created_at
datetime in table tracks
. parameter $timestamp
unix timestamp (an integer).
so trying tracks::where('created_at','>=',$timestamp)->get();
returns tracks, no matter $timestamp specify.
however can see type problem, , have tried different things writing 'unix_timestamp(created_at)' instead of created_at, no luck.
so assume there elegant , simple way of doing this. can me?
there 2 ways solve this.
- use
tracks::where(db::raw('unix_timestamp(created_at)'),'>=',$timestamp)
- use
datetime
orcarbon
object.
like this:
$timestamp = carbon\carbon::createfromtimestamp($timestamp); tracks::where('created_at','>=',$timestamp)->get();
Comments
Post a Comment