Search code examples
phplaravelphp-carbon

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


Solution

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