php 5.3 - php getting seasons programatically -


i have database historic data , i'd sort them out seasons via dates

eg. if season 1 began on 2014-01-01 - 2014-04-30, season 2 on 2014-05-01 - 2014-08-31, season 3 on 2014-09-01 - 2014-12-31, seasons 4, 5 , 6 2015-01-01 - 2015-04-30, 2015-05-01 - 2015-08-31, , 2015-09-01 - 2015-12-31.

it's upping year starting 2014.

i'd want simple using query string of $_get['season'] season=2 , programmatically know 2014-05-01 - 2014-08-31 based on start year.

what's best way this?

so far have code

 <?       $season = $_get['season'];        $endmonth = $season * 4;       $startmonth = $endmonth - 4;       echo "startmonth: " . $startmonth . "<br />";       echo date("y-m-d h:i:s", strtotime("+" . $startmonth . " months", strtotime('2005-01-01 00:00:00'))) . "<br />";       echo date("y-m-d h:i:s", strtotime("+" . $endmonth . " months", strtotime('2005-01-01 00:00:00'))) . "<br />";  ?> 

i need exact on dates

from 'season number' season use modulo calculation: $season = $theseasonnumber % 4

if want know date range of season, start month ending on $endmonth = $season * 3 , starting on $startmonth = $endmonth - 2

from there logic , playing date functions php.

edit based on edited question made working example function

<?php  function season_to_dates($season, $startyear = 2014) {     $year = floor($season / 4); // years on top of startyear      $actual_season = $season % 4; // returns actual season     if($actual_season == 0) $actual_season = 4; // little trick      $endmonth = $actual_season * 3;      $startmonth = $endmonth - 2;       return array(         'season' => $actual_season,         'start' => date("y-m-d", mktime(0,0,0,$startmonth,1,$year+$startyear)),         'end'   => date("y-m-t", mktime(0,0,0,$endmonth,1,$year+$startyear))     ); }   if(!isset($_get['season'])) $season = rand(1,40); else $season = $_get['season'];  echo 'result season ' . $season . '<pre>'; print_r(season_to_dates($season)); echo '</pre>';   ?> 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -