I want to change weekendDays
to only include Sunday in my Carbon Instance. How can I do that?
Carbon also allows us to generate dates and times based on a set of parameters. For example, to create a new Carbon instance for a specific date use the Carbon::createFromDate() method, passing in the year, month, day, and timezone, as in the following example.
$date = Carbon\Carbon::parse($rawDate); well thats it. You'll now have a Carbon instance & you can format the date as you like using Carbon helper functions.
Most web applications require to work with date and time. The web application developed by the Laravel framework uses a simple API extension to work with the date and time called Carbon. This PHP package can handle the time and timezone more easily in the Laravel project.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With