简体   繁体   English

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

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

I just want to get the last 5 days of last month using carbon我只想使用碳来获取上个月的最后 5 天

I'm using this code to get the last day of last month我正在使用此代码获取上个月的最后一天

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

I already search on the internet but I cannot find an answer我已经在互联网上搜索,但我找不到答案

I already have an answer to this我已经有了答案

$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