How would you convert a date string that might be formatted like:
m/d/yyyy H:i:s or mm/dd/yyyy H:i:s
and format it like:
yyyy-mm-dd H:i:s
I can format either of the two inputs into my desired format, but not both.
strtotime() will have no problem parsing these two datetime formats.
Then just use its return unix timestamp integer with date() to generate the desired format string.
function format_date($date) {
return date('Y-m-d H:i:s', strtotime($date));
}
Easiest way would be to simply transform it to unix time first with strtotime then run strftime on it afterwards... not the bes practice but it eliminates alot of the potential format parsing issues :-)
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