When using php DateTime object to get date of the last day of the month, the year is always incorrect.
My code is:
$d = new DateTime();
$d->modify('last day of this month');
$formattedDateTime = $d->format('Y-m-d H:i:s')
Everything is correct apart from the year which is being returned as 7168 instead of 2012.
Anyone any ideas as to what is causing this?
As others have said, it works for me also (PHP 5.4.3). There have been some bugs in the date/time code over some of the more recent PHP versions, though, so try upgrading your installation if possible and see if that helps.
That being said, you should just be passing the string directly to the constructor instead of using
DateTime::modify():