[Solved] Check season of year in php


Just need to format the values o match yours

$someDay = "2018-12-01";

$spring = (new DateTime('March 20'))->format("Y-m-d");
$summer = (new DateTime('June 20'))->format("Y-m-d");
$fall = (new DateTime('September 22'))->format("Y-m-d");
$winter = (new DateTime('December 21'))->format("Y-m-d");

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

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

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

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

Try it online!

0

solved Check season of year in php