You aren't using any library which does natural language processing
. A better option will be to do
$y = date('Y') - 1;
Also, I am worried about the syntax: date('Y'($y...
EDIT
Exactly as I expected, your code doesn't even compile: Parse error: syntax error, unexpected '(' in /scratchpad/index.php on line 3
Try creating a function which does this:
function getYear( $before = 0 ) {
return ( date( 'Y' ) - $before );
}
Even better is to use strtotime
:
function getYear( $context ) {
return date( 'Y', strtotime( $context ) );
}
Then use it something like:
echo ( getYear( '-1 year' ) );
will give: 2014
.