Search code examples
phplaraveldatephp-carbon

How can I change what days Carbon considers the weekend?


I want to change weekendDays to only include Sunday in my Carbon Instance. How can I do that?


Solution

  • Run:

    Carbon::setWeekendDays([Carbon::SUNDAY]);
    

    In your App\Providers\AppServiceProvider in the boot function.

    Edit:

    setWeekendDays is deprecated. Use macro instead.

    Carbon::macro('isDayOff', function ($date) {
       return $date->isSunday();
    });
    
    $isDayOff = $carbon_inst->isDayOff(): bool;