How can substr() function be used to manipulate date formats in PHP?

To manipulate date formats in PHP using the substr() function, you can extract specific parts of the date string and rearrange them to create the desired format. For example, if you have a date in the format "YYYY-MM-DD" and want to convert it to "DD-MM-YYYY", you can use substr() to extract the year, month, and day, and then concatenate them in the desired order.

$date = "2022-01-15";
$new_date = substr($date, 8, 2) . "-" . substr($date, 5, 2) . "-" . substr($date, 0, 4);
echo $new_date; // Output: 15-01-2022