We released a mini package called spatie/holidays that can calculate the public holidays of a country.

ou can get all holidays for a country by using the get method.

use SpatieHolidaysHoliday;

// returns an array of Belgian holidays
// for the current year
$holidays = Holidays::for(‘be’)->get();

Alternatively, you could also pass an instance of Country to the for method.

use SpatieHolidaysHoliday;
use SpatieHolidaysCountriesBelgium;

// returns an array of Belgian holidays
// for the current year
$holidays = Holidays::for(Belgium::make())->get();

You can also pass a specific year.

use SpatieHolidaysHoliday;

$holidays = Holidays::for(country: ‘be’, year: 2024))->get();

If you need to see if a date is a holiday, you can use the isHoliday method.

use SpatieHolidaysHoliday;

Holidays::for(‘be’)->isHoliday(‘2024-01-01’); // true

If you need the name of the holiday, you can use the getName method.

use SpatieHolidaysHoliday;

Holidays::for(‘be’)->getName(‘2024-01-01’); // Nieuwjaar

In closing

We’ve made this package for our own needs and packaged it, so you don’t have to code it up in your project. You can see a list of all packages we’ve made previously on our company website.

Categories: PHP