I am trying to use php datetime object for handling dates.
Here is my code:
$date = new DateTime('01 Dec, 1969');
echo $date->format('Y-m-d');
The above code returns 2010-12-01
But If I change year from 1969 to 1945 or anything less than 1960 then the code returns incorrect year. For example:
This code:
$date = new DateTime('01 Dec, 1950');
echo $date->format('Y-m-d');
returns
2010-12-01
This is likely a bug. Consider filing it to the bugtracker.
When you change the input format to
PHP will correctly make this into
See http://codepad.org/trFfB6Q1
As of PHP5.3, you can also use
DateTime::createFromFormatto create a date. This would work with your original DateTime string then:See http://codepad.viper-7.com/08kK5M