[英]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 .
表中的行还具有一个字段created_at 。 Now I would like to select all rows where the created_date is older than 14 days .
现在,我要选择created_date 早于14天的所有行。 But I'm stuck on how to do this with Carbon .
但是我仍然坚持使用Carbon来做到这一点。 My query now looks like this:
我的查询现在看起来像这样:
$passed = Deployment::where('created_at', '>=', );
Can anyone help me with this? 谁能帮我这个?
您可以使用subDays()
方法:
$passed = Deployment::where('created_at', '<=', Carbon::now()->subDays(14)->toDateTimeString());
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文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.