Forum Moderators: coopster

Message Too Old, No Replies

Season check script, is it correct? plese help.

Echoes today season from four given date windows (not for summer spring...)

         

hisac

3:38 pm on Nov 4, 2005 (gmt 0)

10+ Year Member



<?php
function SeasonCheck()
{
if (date("m-d") >= "04-16" && date("m-d") <= "06-30") {
return "low_1";
}
if (date("m-d") >= "09-01" && date("m-d") <= "12-21") {
return "low_2";
}
if (date("m-d") >= "07-01" && date("m-d") <= "08-31") {
return "high_1";
}
if (date("m-d") >= "12-22" && date("m-d") <= "04-15") {
return "high_2";
}
}
echo SeasonCheck();
?>

jatar_k

4:26 pm on Nov 4, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



is it working? if not what is it doing?

chirp

4:55 pm on Nov 4, 2005 (gmt 0)



I don't see how this could ever be working:

if (date("m-d") >= "12-22" && date("m-d") <= "04-15") {

To use >= and <= you need to have scalar values rather than strings for a start, but that doesn't help in this case when you're wrapping around the end of the year. It also discriminates against either the northern- or southern-hemisphere ;)

hisac

4:56 pm on Nov 4, 2005 (gmt 0)

10+ Year Member



hello,

dates in php is a little bit confusing to me.

I think the scrpt is working.
but how do i know it is not doing 0 = 0.
or is it really 10-30 > 11-01?
is the another way to do the same?

thanks

hisac

5:07 pm on Nov 4, 2005 (gmt 0)

10+ Year Member



Well, this is not to check wheather it is spring or winter i just want to know if todays date is within those periods for the active year.

Thank You.

chirp

9:31 am on Nov 6, 2005 (gmt 0)



This is the approach I'd take:

$day = date('j'); 
$month = date('n');
switch($month) {
case 1:
case 2:
case 3:
return "high_2";
break;
case 4:
return ($day <= 15)? "high_2" : "low_1";
break;
case 5:
case 6:
return "low_1";
break;
case 7:
...
}

;)

hisac

12:57 pm on Nov 7, 2005 (gmt 0)

10+ Year Member



Yes, it makes more sense.

Thank you.