简体   繁体   中英

Get the last 5 days of last month using Carbon

I just want to get the last 5 days of last month using carbon

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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