Moin!
Müssen unter Linux auch Monate erst gemountet werden?
Aber klar doch!
Das Umformen:
return date("Y-m-d", strtotime("$Y-$mounth-1"));
Also kann man auch:
<?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, $format='Y-m-d', $date=false) {
if (false === $date) $date=date('Y-m-d');
list($Y, $M, $dummy) = explode('-', $date, 3);
if ($M <= $mounth) $Y--;
return date($format, strtotime("$Y-$mounth-1"));
}
Jörg Reinholz