繁体   English   中英

使用 Carbon 获取上个月的最后 5 天

[英]Get the last 5 days of last month using Carbon

我只想使用碳来获取上个月的最后 5 天

我正在使用此代码获取上个月的最后一天

$lastDay = new Carbon('last day of last month')

我已经在互联网上搜索,但我找不到答案

我已经有了答案

$lastDay = new Carbon('last day of last month');
$lastMonthDays = [];
$lastDays = $lastDay->format('d') - 5;
$day = $lastDay->format('d');

for($i = $lastDays +1 ; $i <= $day; $i++){
  $lastMonthDays[] = $i;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM