1

I want to get the year of the previous month.

For example in July 2012 I want result 2012. But in January 2013 I want result 2012 and in Feb 2013 I want result 2013

I have searched and found this How to get previous month and year relative to today, using strtotime and date? It uses date_create function (i.e. DateTime Class). But I want a solution without using it. i.e. by using simple date() function

Community
  • 1
  • 1
Imdad
  • 5,942
  • 4
  • 33
  • 53

1 Answers1

4
<?php
echo date('Y', strtotime('-1 month'));

Should work as expected.

Artefact2
  • 7,516
  • 3
  • 30
  • 38