获取创建日期早于 14 天的行
Get rows where created date is older than 14 days
是这样的:
在我的数据库中,我有一个 table deployments。 table 中的行也有一个字段 created_at。现在我想 select created_date 早于 14 天 的所有行。但我一直在思考如何使用 Carbon 来做到这一点。我的查询现在看起来像这样:
$passed = Deployment::where('created_at', '>=', );
谁能帮我解决这个问题?
您可以使用subDays()
方法:
$passed = Deployment::where('created_at', '<=', Carbon::now()->subDays(14)->toDateTimeString());
您可以使用 Carbon::now()->subDays(14)
$passed = Deployment::where('created_at', '>=', Carbon::now()->subDays(14)->toDateTimeString());
您可以在此处详细了解 Carbon 的功能 Carbon Documentation
是这样的:
在我的数据库中,我有一个 table deployments。 table 中的行也有一个字段 created_at。现在我想 select created_date 早于 14 天 的所有行。但我一直在思考如何使用 Carbon 来做到这一点。我的查询现在看起来像这样:
$passed = Deployment::where('created_at', '>=', );
谁能帮我解决这个问题?
您可以使用subDays()
方法:
$passed = Deployment::where('created_at', '<=', Carbon::now()->subDays(14)->toDateTimeString());
您可以使用 Carbon::now()->subDays(14)
$passed = Deployment::where('created_at', '>=', Carbon::now()->subDays(14)->toDateTimeString());
您可以在此处详细了解 Carbon 的功能 Carbon Documentation