I have a date in this format:
20110122000000.000
how can I change that so it's
12.01.2011
(12 January 2011)
Then I use this in php:
$origDate = "20110112000000.000";
$newDate = date("d.m.Y", strtotime($origDate));
it can output something like:
01.12.2011
Thanks!
If you are using >= PHP 5.3
$date = DateTime::createFromFormat('Ymd', '20110112000000.000');
echo $date->format('d.m.Y');
I can't test PHP 5.3 here, so if that extraneous stuff is playing up createFromFormat()
, just remove it first.
I don't know about all your formats, but this will remove all 0
and .
at the end of your string.
$date = rtrim($date, '.0')
And because the most significant number is always on the right, (2
in this example), it shouldn't be a problem.
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