How to find the last Monday 2 months ago or N months ago

I can find the last Monday of the previous month, but I also need two months ago last Monday?

strtotime("last Monday of June 2015") //gives previous month last Monday

      

What should I do to find -2 months last Monday?

I will use this programmatically

+3


source to share


2 answers


Try the following:

// Past
strtotime("last Monday of -2 months");

// Future
strtotime("last Monday of +2 months");

      



Works like a charm! PHP is strtotime

very smart.

+3


source


Dirty in my opinion, but it works

$no_months = -2; // Number of months from now
echo date('d/M/Y' , strtotime('Last monday of ' . date('M Y', strtotime($no_months . ' months'))));

      



Basically, this just dynamically creates a portion of your original string "June 2015", "May 2015" based on the negative / positive months given in var.

+2


source







All Articles