Laravel上个月获取碳数据

问题描述 投票:1回答:1

我正在尝试从我的数据中获取第一个结果,其中日期等于上个月的日期范围。

这是我的数据库内容的例子 -

id  date_recorded
1   2016-07-22 15:21:33
2   2016-08-13 12:22:22
3   2016-07-06 12:22:22
4   2016-09-12 12:45:22

这是我获取第二个结果的查询(上个月的最新结果)。

$seoScoreLastMonth = Manual::where('account_id', Auth::user()->account)
->where('date_recorded', '>=', Carbon::now()->subMonth())
->orderBy('date_recorded', 'desc')
->pluck('seo_score')
->first();

返回的结果为null,这是因为id中数据库中的第一个结果与日期不匹配?

php mysql laravel eloquent php-carbon
1个回答
1
投票

我这个月需要。这是我的查询。我想如果你需要,你可以修改它

$start = new Carbon('first day of this month');
$start = $start->startOfMonth()->format('Y-m-d H:i:s'); // startOfMonth for 00:00 time

你的query..->where('date_recorded','>',$start)..

Carbon - get first day of month enter link description here的帮助下

© www.soinside.com 2019 - 2024. All rights reserved.