How to get previous year using PHP

Solution 1:

try

echo date("Y",strtotime("-1 year"));

Solution 2:

$year = date("Y");
$previousyear = $year -1;

http://php.net/manual/de/function.date.php

Solution 3:

There are many ways, you can either take away the amount of seconds in a year from time() like so:

$prevYear = date('Y', time() - 60*60*24*365 );

Or if you'd prefer, use the PHPs clever strtotime() function:

$prevYear = date('Y', strtotime('-1 year'));

Or even like others have said, if it's from todays year just do date('Y') -1

Solution 4:

Shortest approach:

$lastYear = (int)date("Y") - 1;