Sevalla is the all-in-one PaaS for your web projects. Host and deploy your applications, databases, object storage, and static sites. Enjoy advanced deployment pipelines, a complete database studio, instant preview apps, and one-click templates. The pricing is simple: no hidden fees, no seat-based pricing, and you pay only for what you use. Get real human support from developers.

Get started now with a $50 credit at Sevalla.com.

A mini package to calculate public holidays in a country

Original – by Freek Van der Herten – 2 minute read

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 Spatie\Holidays\Holiday;

// 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 Spatie\Holidays\Holiday;
use Spatie\Holidays\Countries\Belgium;

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

You can also pass a specific year.

use Spatie\Holidays\Holiday;

$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 Spatie\Holidays\Holiday;

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

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

use Spatie\Holidays\Holiday;

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.

Stay up to date with all things Laravel, PHP, and JavaScript.

You can follow me on these platforms:

On all these platforms, regularly share programming tips, and what I myself have learned in ongoing projects.

Every month I send out a newsletter containing lots of interesting stuff for the modern PHP developer.

Expect quick tips & tricks, interesting tutorials, opinions and packages. Because I work with Laravel every day there is an emphasis on that framework.

Rest assured that I will only use your email address to send you the newsletter and will not use it for any other purposes.