I have this date as a string: 10.21.2011, the format is mm.dd.yyyy
How can I convert this to Y-m-d? This is what I tried, but it always gives me the 1970 date.
$date = date('Y-m-d', strtotime($date));
Thanks!
The object-oriented way:
$date = DateTime::createFromFormat('m.j.Y', '10.21.2011');
echo $date->format('Y-m-d');
My opinion is that this is the approach one should try to learn with PHP.
Requires PHP 5.3.
Most likely because of period .
:
$date = '10.21.2011';
echo date('Y-m-d', strtotime(str_replace('.', '/', $date)));
Result:
2011-10-21
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With