Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get rows where created date is older than 14 days

This is the case:

In my database I have a table deployments. The rows in the table also have a field created_at. Now I would like to select all rows where the created_date is older than 14 days. But I'm stuck on how to do this with Carbon. My query now looks like this:

$passed = Deployment::where('created_at', '>=', );

Can anyone help me with this?

like image 640
nielsv Avatar asked Dec 07 '15 16:12

nielsv


2 Answers

You can use the subDays() method:

$passed = Deployment::where('created_at', '<=', Carbon::now()->subDays(14)->toDateTimeString());
like image 120
Alex Avatar answered Nov 08 '22 09:11

Alex


You can use Carbon::now()->subDays(14)

    $passed = Deployment::where('created_at', '>=', Carbon::now()->subDays(14)->toDateTimeString());

You can read more about Carbon its feature here Carbon Documentation

like image 39
Mauran Muthiah Avatar answered Nov 08 '22 08:11

Mauran Muthiah