tags:

views:

35

answers:

2

hey guys, what's you take on this.

i want to set a header image on my website (one for winter and one for summer) based on wheter it is a wintermonth or a summermont.

so i wonder what would be the easiest way to that? i thougth of using date('n') and query wheter the returned value is true for a winter or summermonth.

what would you do?

thank you for your tips.

+3  A: 

Googled and found http://www.geekpedia.com/code152_Get-The-Current-Season.html

function GetSeason() {
   $SeasonDates = array('/12/21'=>'Winter',
                        '/09/21'=>'Autumn',
                        '/06/21'=>'Summer',
                        '/03/21'=>'Spring',
                        '/12/31'=>'Winter');
   foreach ($SeasonDates AS $key => $value) // Loop through the season dates
   {
       $SeasonDate = date("Y").$key;
       if (strtotime("now") > strtotime($SeasonDate)) // If we're after the date of the starting season
       {
           return $value;
       }
   }
}

Seems legit, it could probably be condensed a little but I'll leave that as an exercise to the reader.

David Titarenco
+1  A: 

Yeah you should use date('n'). For example like this:

function get_image()
{
    $summer = array(4,5,6,7,8,9);
    return in_array(date('n'), $summer) ? 'summer.png' : 'winter.png';
}
captaintokyo