Get rows where created date is older than 14 days

nielsv picture nielsv · Dec 7, 2015 · Viewed 10.8k times · Source

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?

Answer

Alex picture Alex · Dec 7, 2015

You can use the subDays() method:

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