I have used this :

$date = date("Y-m", strtotime("-2 months"));

and it is gives "2016-12" but what i needed is "2016-11".

closed as off-topic by No Sssweat, DRUPWAY, Krishna Mohan, Pierre.Vriens, kiamlaluno Jan 31 '17 at 9:52

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on programming, PHP, SQL, etc. that do not relate directly to Drupal are off-topic here, but can be asked on Stack Overflow." – No Sssweat, DRUPWAY, Krishna Mohan, Pierre.Vriens, kiamlaluno
If this question can be reworded to fit the rules in the help center, please edit the question.


If you try to change format to dmY for example: echo date("dmY", strtotime("-2 months")); You will see that result is 01122016.

You can check comments from this question also: https://stackoverflow.com/questions/10586615/current-date-2-months

And you can check solution here: https://stackoverflow.com/questions/9058523/php-date-and-strtotime-return-wrong-months-on-31st

Pass second parameter.


I have used :

$fdate = date('Y-m', strtotime('first day of -2 month'));

  • This is working for me – vijay Feb 14 '17 at 7:31

Not the answer you're looking for? Browse other questions tagged or ask your own question.