Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

andyandy's avatar

Carbon week starts at Sunday globally

I have middleware where I'm setting locale:

        if (something)
            Carbon::setlocale('fr');

        if (something)
            Carbon::setlocale('en');

And I want also set start of the week at Sunday, no matter current locale (now EN starts Sunday and FR starts Monday).

I found this, but it is deprecated and I can't figure out to use suggested solutions:

// deprecated
Carbon::setWeekStartsAt(Carbon::MONDAY);

// error message
@deprecated To avoid conflict between different third-party libraries, static setters should not be used.
 *             Use $weekEndsAt optional parameter instead when using endOfWeek method. You can also use the
 *             'first_day_of_week' locale setting to change the start of week according to current locale
 *             selected and implicitly the end of week.
0 likes
7 replies
andyandy's avatar

How do I force Carbon to make Sunday start of the week across all locales?

1 like
andyandy's avatar

@vincent15000 Nope, that post recommends Carbon::setWeekStartsAt(Carbon::FRIDAY); an as I said in my initial post this function is deprecated.

2 likes
vincent15000's avatar

@andyandy Yes but this post is only an example, you can change the day according to your needs.

Carbon::setWeekStartsAt(Carbon::MONDAY);
Carbon::setWeekStartsAt(Carbon::TUESDAY);
Carbon::setWeekStartsAt(Carbon::WEDNESDAY);
Carbon::setWeekStartsAt(Carbon::THURSDAY);
Carbon::setWeekStartsAt(Carbon::FRIDAY);
Carbon::setWeekStartsAt(Carbon::SATURDAY);
Carbon::setWeekStartsAt(Carbon::SUNDAY);
iftekhs's avatar

Can you try this -> https://github.com/briannesbitt/Carbon/issues/1981

Here they call the function but not in static way ->

$en = CarbonImmutable::now()->locale('en_US');

// We still can force to use an other day as start/end of week
$start = $en->startOfWeek(Carbon::TUESDAY); // Start of week assuming Tuesday is the first day of week
$end = $en->endOfWeek(Carbon::MONDAY); // End of week assuming Monday is the last day of week
2 likes
jamesautodude's avatar

Still can't seem to set it globally, so the easiest way I found for now is to just call it in your chain like:

now()->startOfWeek(Carbon::SUNDAY)

1 like

Please or to participate in this conversation.