format in php date code example
Example 1: php change date format
To convert the date-time format PHP provides strtotime() and date() function. We change the date format from one format to another.
Change YYYY-MM-DD to DD-MM-YYYY
<? php.
$currDate = "2020-04-18";
$changeDate = date("d-m-Y", strtotime($currDate));
echo "Changed date format is: ". $changeDate. " (MM-DD-YYYY)";
?>
Example 2: php all date formats
<?php
echo date("F j, Y, g:i a")."<br>";
echo date("m.d.y")."<br>";
echo date("j, n, Y")."<br>";
echo date("Ymd")."<br>";
echo date('h-i-s, j-m-y, it is w Day')."<br>";
echo date('\i\t \i\s \t\h\e jS \d\a\y.')."<br>";
echo date("D M j G:i:s T Y")."<br>";
echo date('H:m:s \m \i\s\ \m\o\n\t\h')."<br>";
echo date("H:i:s")."<br>";
echo date("Y-m-d H:i:s")."<br>";