mardi 24 janvier 2017

Get records within a specific timeframe in Laravel

On my website, I use Laravel's created_at to store the time at which images are uploaded.

However, I want to be able to create a query that gets images only within a specific time frame.

Those would be:

-The past 24 hours

-The past week

-The past month

-The path year

I was thinking of something like...

$images = Images::where('created_at', '>=', Carbon::now()->hours(24))->get();

It would be easy to get records from within specific hours, since I could simply go from 24 to 168 to 672 to 2087 (day, week, month, year).

Thoughts?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire