0 points

Convert one date format into another in PHP


Sat Jan 04 2020 18:42:11 GMT+0000 (UTC)

Posted by @Catsndogs #php #webdev #howto

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

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.