Re: Checking the season

From: Date: Sun, 06 Jan 2002 04:17:24 +0000
Subject: Re: Checking the season
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-79596@lists.php.net to get a copy of this message
Hi This should work: <? $year = date("Y"); $spring = mktime (0,0,0,3,21,$year); $summer = mktime (0,0,0,6,21,$year); $autumn = mktime (0,0,0,9,21,$year); $winter = mktime (0,0,0,12,21,$year); $now = mktime(); if($now < $spring || $now >= $winter):
        echo "Winter";
elseif($now >= $autumn):
        echo "Autumn";
elseif($now >= $summer):
        echo "Summer";
else:
        echo "Spring";
endif; ?> BTW There may be a bug in mktime() (php4) if you use 08 or 09 in the month part...on my system this happens (linux/apache/php4.1) <? $autumn = mktime (0,0,0,09,21,2002); echo "date = ".date("d/m/Y",$autumn)."<br>"; ?> This prints: date = 21/12/2001 Also prints the same date for a month of 08 Tom At 11:34 AM 6/01/02, webapprentice wrote:
I'll have to use and if/elseif construct, because I don't believe a switch() constructs cases can take expressions, can it? ----- Original Message ----- From: "Bogdan Stancescu" <mgv@fx.ro> To: "webapprentice" <webapprentice@onemain.com> Cc: <php-general@lists.php.net> Sent: Saturday, January 05, 2002 11:38 AM Subject: Re: [PHP] Checking the season You could do a case() or if/elseif, check if it's spring, summer or autumn and leave the code for winter as default/else. Bogdan webapprentice wrote:
Hi, Just need a sounding board to help me think this through. I want to check the current date to determine what "season" it is and
display the appropriate picture.
I define spring as 03/21/YYYY, summer as 06/21/YYYY, autumn as
09/21/YYYY, and winter as 12/21/YYYY.
I form a string for the current date and get a timestamp via mktime(). I also get the equivalent timestamps for the dates above for the
seasonal changes.
Then, I compare the current date to see if it's between the seasonal
dates.
The problem is when I go from 12/31/YYYY to 01/01/(YYYY+1). Since winter and spring dates are one year apart, the current date
timestamp comparison gets messed up and nothing displays.
How do I do a proper comparison? I was thinking of just seeing if the
current date timestamp is greater than each of the seasonal date timestamp, but it feels like I would miss something. Would I? Or is there another solution?
Thank you for your time. --Stephen
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net


« previous php.general (#79596) next »