Question and answer is powered by AnsPress.io
I want to get the previous year from the current year in PHP
If current year
echo "2022"
I want the previous year
echo "2021"
How did I get the previous year in my PHP code?
If you are using PHP to display year value. This code will helpful for you.
To display the current year:
echo date("Y");
Output: 2022
To get the previous year from the current year in PHP, apply this code
echo date("Y",strtotime("-1 year"));
Output: 2021