SirChick Posted October 20, 2007 Share Posted October 20, 2007 Hey guys, I'm trying to work out a method where by depending on the date of now at any moment... if the months are in winter then echo winter and months are in spring echo spring etc for all 4 seasons... some method of checking the month number im assuming is how its done? How would you recommend doing this most efficiently? Quote Link to comment https://forums.phpfreaks.com/topic/74079-solved-get-season-type-by-date/ Share on other sites More sharing options...
AndyB Posted October 20, 2007 Share Posted October 20, 2007 $this_month = date("n"); // month number 1-12 There's your start. Quote Link to comment https://forums.phpfreaks.com/topic/74079-solved-get-season-type-by-date/#findComment-373979 Share on other sites More sharing options...
SirChick Posted October 20, 2007 Author Share Posted October 20, 2007 is date("n") a built in function to get the number of the month? Or do i have to set "n" also ? Quote Link to comment https://forums.phpfreaks.com/topic/74079-solved-get-season-type-by-date/#findComment-373983 Share on other sites More sharing options...
AndyB Posted October 20, 2007 Share Posted October 20, 2007 built in .. as are a whole bunch of others -> http://ca.php.net/manual/en/function.date.php Quote Link to comment https://forums.phpfreaks.com/topic/74079-solved-get-season-type-by-date/#findComment-373986 Share on other sites More sharing options...
SirChick Posted October 20, 2007 Author Share Posted October 20, 2007 Thankyou Andy.. I can do the rest just needed to know how to obtain months. Sorted. Quote Link to comment https://forums.phpfreaks.com/topic/74079-solved-get-season-type-by-date/#findComment-373987 Share on other sites More sharing options...
Psycho Posted October 20, 2007 Share Posted October 20, 2007 <?php $seasonList = array ('Winter', 'Spring', 'Summer', 'Fall'); //Set $month to the current month or 0 for Dec $month = (date('n')<12)?date('n'):0; $season = $seasonList[floor($month/3)]; echo $season; //Output (for October):Fall ?> Quote Link to comment https://forums.phpfreaks.com/topic/74079-solved-get-season-type-by-date/#findComment-373989 Share on other sites More sharing options...
AndyB Posted October 20, 2007 Share Posted October 20, 2007 Don't forget that mjdamato's code as shown works only in the northern hemisphere Quote Link to comment https://forums.phpfreaks.com/topic/74079-solved-get-season-type-by-date/#findComment-373991 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.