Check Season Of Year In Php
I want to print a different image every season of the year. Based on a date from my database. I want to print it in php/html5. Found some things on the internet but none of them wo
Solution 1:
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!';
}
Post a Comment for "Check Season Of Year In Php"