Get UK Bank Holidays in PHP

If you’ve ever needed to display opening times for a business on their website you’ll probably have encountered the edge case of differing opening times on UK Bank Holidays. The UK government provides information regarding all UK Bank Holidays, and we’ve written a small open-source PHP library to take advantage of this.


You can install the PHP UK Bank Holidays package using Composer. If you’ve never used Composer before, you can find more information on the Composer website.

To install this package, just run the following command from the root of your project.

composer require rapidwebltd/php-uk-bank-holidays

Getting data for all UK bank holidays

Once installed, you can get information for all bank holidays in a specific location using the getAll method of the UkBankHolidayFactory.

$englandWalesHolidays = UkBankHolidayFactory::getAll('england-wales');
$scotlandHolidays = UkBankHolidayFactory::getAll('scotland');
$northernIrelandHolidays = UkBankHolidayFactory::getAll('northern-ireland');

Note that if you only wish to get bank holidays from England & Wales, you can optionally leave out the location parameter.

Getting UK bank holidays for a specific date

If needed, you can also specify a date and retrieve any Bank Holidays that are present on that date. To do this, you can use the getByDate method, as follows.

$newYearsHolidays = UkBankHolidayFactory::getByDate(2017, 01, 2, 'england-wales');

You can also restrict by month, as in the example below.

$januaryHolidays = UkBankHolidayFactory::getByMonth(2017, 01, 'england-wales');

UkBankHoliday object

All methods described above will return an array of UkBankHoliday objects that are appropriate for the specified date and location restrictions. An example of the returned array is provided below.

array(1) {
  object(RapidWeb\UkBankHolidays\Objects\UkBankHoliday)#46 (4) {
    string(16) "New Year’s Day"
    string(10) "2017-01-02"
    string(14) "Substitute day"

The object contains the title of the holiday, the date is falls upon and any other government provided notes regarding the bank holiday.

Open Source & Contribution

For more usage examples, or to contribute to the project, head to the PHP UK Bank Holidays GitHub page. Contributions are most welcome.

Rapid Web Services make this PHP library available for free, as open source software under a LGPL-3.0 license. Take a look at the Rapid Web Services open source software page for more of our open source projects.