0

I have theater shows dates in several cultural seasons.

A cultural season is from the first day of September to the last day of August.

Using PHP, I need to know the year of the "last first day of September" relative to the date of the show to assign the right season to the show.

E.g.:

15/05/2009 -> 01/09/2008 : season 2008-2009
21/06/2013 -> 01/09/2012 : season 2012-2013
27/10/2013 -> 01/09/2013 : season 2013-2014
Dharman
  • 30,962
  • 25
  • 85
  • 135
yom
  • 13
  • 5

2 Answers2

1

Try this out... will give you start start year for the period.

$targetTime = strtotime("2013-06-05");
$sept1 = strtotime("September 1st", $targetTime);
if ($targetTime < $sept1){
    $sept1 = strtotime("-1 Year", $sept1);
} 
$year =  date("Y", $sept1);
Orangepill
  • 24,500
  • 3
  • 42
  • 63
0
<?php


function season($date)
{

    if($date->format('m') < 9)
        return $date->format('Y') -1;

    else
        return $date->format('Y') ;

}


$date = new DateTime();
$date->setDate(2008, 9, 1);
$season = season($date);
echo 'season ' . $season . '/' . ($season + 1);

?>
Rafael Azevedo
  • 330
  • 2
  • 8