Switch Hero-Image on Winter and Sommer of a year

hej. i want to enable a if else syntax to my block-element.
the editor has 2 options to upload an image for winter and for summer.

in the template output i will use the right image by date.
how can I define a range of the first year of 182 days?

I think I would define “seasons” in my template and show the images accordingly.

Something like this (stolen from PHP: How to check the season of the year and set a class accordingly - Stack Overflow)

// get today's date
$today = new DateTime();
echo 'Today is: ' . $today->format('m-d-Y') . '<br />';

// get the season dates
$spring = new DateTime('March 20');
$summer = new DateTime('June 20');
$fall = new DateTime('September 22');
$winter = new DateTime('December 21');

switch(true) {
    case $today >= $spring && $today < $summer:
        echo 'It\'s Spring!';
        break;

    case $today >= $summer && $today < $fall:
        echo 'It\'s Summer!';
        break;

    case $today >= $fall && $today < $winter:
        echo 'It\'s Fall!';
        break;

    default:
        echo 'It must be Winter!';
}
1 Like

If you are targeting a worldwide audience, you might want to take different winter/summer dates in the Southern Hemisphere into account as well.