Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP strtotime( YYYY-mm last day) a month off error

I'm trying the following command in PHP 5.2.12 :

print (date('Y-m-d', strtotime('2009-12 last day')));

Regarding to the php.net manual :

date('m/d/y', strtotime('2009-03 last day')); # 03/31/09

it should display the last day of march 2009 (2009-03-31) !

Mine returns the last day of the previous month ? why ? :

2009-11-30
like image 665
Kami Avatar asked Dec 22 '22 04:12

Kami


1 Answers

The code you posted fails in the manner you described; it seems that the description in the PHP manual pages (which as mentioned by SilentGhost is just a user comment) is non-verified code.

If you need the last day of a given month, try this:

date('Y-m-d', strtotime("2009-12 next month - 1 hour"));
like image 199
Roadmaster Avatar answered Jan 08 '23 06:01

Roadmaster