Convert one date format into another in PHP

PHOTO EMBED

Sat Jan 04 2020 18:42:11 GMT+0000 (Coordinated Universal Time)

Saved by @Catsndogs #php #webdev #howto

$myDateTime = DateTime::createFromFormat('Y-m-d', $dateString);
$newDateString = $myDateTime->format('m/d/Y');
content_copyCOPY

You are first giving it the format $dateString is in. Then you are telling it the format you want $newDateString to be in. This also avoids the use of strtotime, which can be hard to work with at times.

https://stackoverflow.com/questions/2167916/convert-one-date-format-into-another-in-php