0 points

Convert one date format into another in PHP


dashboard

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

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

>> Browse more code snippets

more_vert