【问题标题】:Get the last 5 days of last month using Carbon使用 Carbon 获取上个月的最后 5 天
【发布时间】:2019-11-06 09:59:19
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: php laravel php-carbon


    【解决方案1】:

    我已经有了答案

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

    【讨论】:

      猜你喜欢
      • 2016-09-06
      • 2019-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多