How to reverse date in PHP

To reverse the date from the format “yyyy-mm-dd” to “mm-dd-yyyy” in PHP, you can use the following script:

<?php
$date = "2023-07-04";

// Reversing the date format
$reversedDate = date("m-d-Y", strtotime($date));

echo "Original date: " . $date . "<br>";
echo "Reversed date: " . $reversedDate;
?>

In this script, the variable $date holds the original date in the “yyyy-mm-dd” format. The date() function is then used to convert and format the date. By passing the $date variable to strtotime(), it is converted to a Unix timestamp, which can be easily manipulated. The date() function then reformats the timestamp to the desired “mm-dd-yyyy” format. Finally, the original and reversed dates are printed on the screen.