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>'); ?> Link to comment https://forums.phpfreaks.com/topic/77891-solved-compare-dates/ 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. Link to comment https://forums.phpfreaks.com/topic/77891-solved-compare-dates/#findComment-394319 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 Link to comment https://forums.phpfreaks.com/topic/77891-solved-compare-dates/#findComment-394337 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? Link to comment https://forums.phpfreaks.com/topic/77891-solved-compare-dates/#findComment-394420 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 Link to comment https://forums.phpfreaks.com/topic/77891-solved-compare-dates/#findComment-394455 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 Link to comment https://forums.phpfreaks.com/topic/77891-solved-compare-dates/#findComment-395620 Share on other sites More sharing options...
pkSML Posted November 21, 2007 Share Posted November 21, 2007 Glad to help. Link to comment https://forums.phpfreaks.com/topic/77891-solved-compare-dates/#findComment-395772 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.