Jesus Jesus - 2 months ago 24
PHP Question

PHP Convert datetime format

Is there a way in PHP to convert the date time format from the one in the left to the one on the right?

1900-01-01T00:00:00-06:00 to 1900-01-01 00:00:00.000

2015-06-18T00:00:00-05:00 to 2015-06-18 00:00:00.000

As you see I don't want to keep the timezone and want to get rid of the T and I believe the one in the right also has milliseconds.

Answer

Since only the year month and day are pertinent, you can just use date_format to get that from your existing string, then concatenate your time to it, resulting in the string you're after.

date_format(new DateTime("1900-01-01T00:00:00-06:00"),"Y-m-d")." 00:00:00.000";
// 1900-01-01 00:00:00.000