Bizzarre and slightly annoying PHP date increment problem.

Soldato
Joined
20 Feb 2004
Posts
4,035
Location
Blyth, Northumberland
I have the following code which works fine:

Code:
$currentSeason = date ('Y') - 1 . "-" . date ('Y');

The output I get is "2007-2008" as expected.

For some reason the following code doesn't want to work:

Code:
$currentSeason = date ('Y') . "-" . date ('Y') + 1;

The output I get is "2009" :confused: It should be "2008-2009". I think I've coded it incorrectly but can't see where I've gone wrong.
 
$aaa = date ('Y');
$bbb = date ('Y') - 1;
$ccc = date ('Y') + 1;

$currentSeason = $bbb . '-' . $aaa;
$currentSeason2 = $aaa . '-' . $ccc;

echo $currentSeason;
echo $currentSeason2;

Will work...

Example of course...

$currentSeason will output - 2007 - 2008
$currentSeason2 will output 2008 - 2009
 
Back
Top Bottom