Given: date of December 31, 2004. Task: determine the date, which was three months ago. In MySQL we think so:
SELECT DATE_SUB('2004-12-31', INTERVAL 3 MONTH) We get 2004-09-30. This date suits us and we want to get it at the PHP level:
$maxDate = '2004-12-31'; $timestamp = ; echo date('Ym-d', strtotime($maxDate . ' - 3 month')); We get 2004-10-01. It is logical, but not quite what we expect.
We try differently:
$Date = new DateTime('2004-12-31'); $Date->sub(DateInterval::createFromDateString('3 months')); echo $Date->format('Ym-d'); Again, we get October 1.
How, without a garden, in PHP to get the expected date?