Holidays based on a given date range

Let's say you are running an online store, and you want to send shoppers a promotion e-mail about new seasonal products. Yasumi can help you find holidays that occur in a certain date range.

For your shoppers in Italy, you would like to know which holidays occur in December. Simply use the Yasumi 'BetweenFilter' class like this:


// Require the composer auto loader
require 'vendor/autoload.php';

$year = 2020;

// Use the factory to create a new holiday provider instance
$holidays           = Yasumi\Yasumi::create('Italy', $year);
$holidaysInDecember = $holidays->between(
                        new DateTime('12/01/' . $year),
                        new DateTime('12/31/' . $year)

We then can see the following holidays in Italy in December:

foreach ($holidaysInDecember as $holiday) {
    echo $holiday . ' - ' . $holiday->getName() . PHP_EOL;

// 2020-12-08 - Immaculate Conception
// 2020-12-25 - Christmas
// 2020-12-26 - St. Stephen's Day

Using this, you can select new products that you would like to promote to your shoppers. Simple as that!

Use the count() method to show how many holidays are present:

echo $holidaysInDecember->count();

// 3

Yasumi works only with holidays for the year you have specified when creating the holiday provider instance. This means that if you use either a start or end date beyond this year, holidays before or after the given year will not be retrieved.

Last updated 01/12/2021