How to get a previous year in PHP
In this tutorial, we are going to learn about how to get the previous year in PHP.
Getting the previous year
To get the previous year in PHP. first, we need to access the current year using the built-in date("Y")
function then we need to subtract it with minus 1.
The
date("Y")
function returns the current year in four-digit(2024) string format according to the user’s local time.
Here is an example:
$currentYear = date("Y");
$previousYear = $currentYear-1;
echo $previousYear;
Output:
2023