Jörg Reinholz: strtotime() letzter August gesucht

Beitrag lesen

Moin!

Sowas?

<?php
#Test:
echo firstDayOfMounthAgo(1, '2016-01-11'), "\n";
echo firstDayOfMounthAgo(1), "\n";
echo firstDayOfMounthAgo(1, '2016-02-13'), "\n";
echo firstDayOfMounthAgo(1, '1970-02-13'), "\n";


function firstDayOfMounthAgo ($mounth, $date=false) {
  if (false === $date) $date=date('Y-m-d');
  list($Y, $M, $dummy) = explode('-', $date, 3);
  if ($M <= $mounth)    $Y--;
  return ("$Y-$mounth-1");
}

Ergebnisse:

2015-1-1
2015-1-1
2016-1-1
1970-1-1

Weitere Umformungen kannst Du selbst ...

Jörg Reinholz