laravel 获取创建日期早于 14 天的行

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34138194/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:47:05  来源:igfitidea点击:

Get rows where created date is older than 14 days

phplaraveldatetimelaravel-5.1php-carbon

提问by nielsv

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:

在我的数据库中,我有一个表部署。表中的行也有一个字段created_at。现在我想选择 created_date早于 14 days 的所有行。但我被困在如何用Carbon做到这一点。我的查询现在看起来像这样:

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

Can anyone help me with this?

谁能帮我这个?

回答by Alex

You can use the subDays()method:

您可以使用以下subDays()方法:

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

回答by Mauran Muthiah

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

您可以使用 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

您可以在此处阅读有关 Carbon 其功能的更多信息Carbon 文档