3

I just tried to subtract 6 and 5 months respectively from current date 08/29/2015 @ 11:19am (UTC) and got the same result

Here is the code sample:

date("M, Y", strtotime("-5 months")) // returns Mar, 2015
date("M, Y", strtotime("-6 months")) // returns Mar, 2015

Is it due to day light saving? I think No.

Rizier123
  • 58,877
  • 16
  • 101
  • 156
Muaaz Khalid
  • 2,199
  • 2
  • 28
  • 51

2 Answers2

2
date("M, Y", strtotime("-6 months"))

Simply returns also Mar, 2015 because there was no 29. February this year. So it takes the next month which is March.

To solve this just do it always from the first day of the month, e.g.

echo date("M, Y", strtotime("-6 months", strtotime(date('Y-m-01'))));
                                       //^^^^^^^^^^^^^^^^^^^^^^^^^ First day of month
Rizier123
  • 58,877
  • 16
  • 101
  • 156
0

This is the only working option i could find for you. How to subtract 4 months from today's date?

echo date("Ymd", mktime(0, 0, 0, date("m")-5, date("d"),   date("Y")));;
Community
  • 1
  • 1
kurt
  • 1,146
  • 1
  • 8
  • 18
  • `echo date("Ymd", strtotime("-5 months"));` returns 20150329 and `echo date("Ymd", strtotime("-6 months"));` returns 20150301 Both with third month – Muaaz Khalid Aug 29 '15 at 11:31
  • updated my answer. It really beats me. Weird problem – kurt Aug 29 '15 at 11:41