samedi 31 mars 2018

PHP- get the last 6 months from the current date

I am trying to get the last six months from the current date in PHP. It's a simple problem, but my code is not giving the right result.

for ($j = 0; $j <= 5; $j++) {
    echo date("F Y", strtotime(" -$j month"));
    echo "<br>";
}

And the output is

March 2018
March 2018
January 2018
December 2017
December 2017
October 2017

I dont understand why March is coming twice.




Aucun commentaire:

Enregistrer un commentaire