mdawg Posted November 19, 2007 Share Posted November 19, 2007 Hi Everyone, I'm new to this forum. I hope this is the right place for my question. Background: I need to populate a variable with the correct season (fall, spring, summer, or winter). I will use this to point to the correct image folder. Here's what I have so far, but for some reason does not work correctly. Any thoughts/suggestions would be great. View source below...thanks in advance. If you know of a better way (I know there is) please let me know. <?php $todayDate = date('y-m-d'); $currYear = date('y-'); $fallSeason = $currYear . '09-22'; $springSeason = $currYear . '03-21'; $winterSeason = $currYear . '12-22'; $summerSeason = $currYear . '06-21'; $season = ''; // convert date with strtotime() function $today = strtotime($todayDate); $fall = strtotime($fallSeason); $spring = strtotime($springSeason); $winter = strtotime($winterSeason); $summer = strtotime($summerSeason); if ($today > $fall) { $season = "fall"; } else if ($today > $spring) { $season = "spring"; } else if ($today > $winter) { $season = "winter"; } else { $season = "summer"; } // Everything below is for display only if ($today > $fall) { echo ('<h1>It\'s true: fall</h1>'); } else { echo ('<h1>not fall</h1>'); } if ($today > $spring) { echo ('<h1>It\'s true: spring</h1>'); } else { echo ('<h1>not spring</h1>'); } if ($today > $winter) { echo ('<h1>It\'s true: winter</h1>'); } else { echo ('<h1>not winter</h1>'); } if ($today > $summer) { echo ('<h1>It\'s true: summer</h1><hr>'); } else { echo ('<h1>not summer</h1><hr>'); } echo ('<h1>Today\'s Date: ' . $today . '</h1>'); echo ('<h1>Today\'s Season: ' . $season . '</h1><hr>'); echo ('<h1>Fall: ' . $fall . '</h1>'); echo ('<h1>Spring: ' . $spring . '</h1>'); echo ('<h1>Winter: ' . $winter . '</h1>'); echo ('<h1>Summer: ' . $summer . '</h1>'); ?> Quote Link to comment Share on other sites More sharing options...
btherl Posted November 19, 2007 Share Posted November 19, 2007 How does it not work correctly? It tells me the current season is fall, which sounds about right for the northern hemisphere. Quote Link to comment Share on other sites More sharing options...
rajivgonsalves Posted November 19, 2007 Share Posted November 19, 2007 well seeing your code if ($today > $fall) { echo ('<h1>It\'s true: fall</h1>'); } else { echo ('<h1>not fall</h1>'); } you will have to specify a range like fall is between October to december otherwise looking at you code it would override. consider the following if ($today > $fall && $today < $spring) { echo ('<h1>It\'s true: fall</h1>'); } else { echo ('<h1>not fall</h1>'); } hope its helpful Quote Link to comment Share on other sites More sharing options...
pkSML Posted November 19, 2007 Share Posted November 19, 2007 Background: I need to populate a variable with the correct season (fall, spring, summer, or winter). I will use this to point to the correct image folder. If you know of a better way (I know there is) please let me know. http://code-bin.homedns.org/62 This what you're looking for? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 19, 2007 Share Posted November 19, 2007 http://code-bin.homedns.org/62 That code was short enough to post in your reply here. Why take us to another site just to see it? Ken Quote Link to comment Share on other sites More sharing options...
mdawg Posted November 21, 2007 Author Share Posted November 21, 2007 pkSML, Thanks...that works great and very simple. Everyone...thanks for your input and fast response. SOLVED!!! mdawg Quote Link to comment Share on other sites More sharing options...
pkSML Posted November 21, 2007 Share Posted November 21, 2007 Glad to help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.