How can PHP be used to extract and display specific parts of a date, such as the day and month, from a given variable?

To extract and display specific parts of a date in PHP, you can use the date() function along with the desired format characters. For example, to extract and display the day and month from a given date variable, you can use 'd' for the day and 'm' for the month within the date() function.

$date = "2022-09-15";
$day = date('d', strtotime($date));
$month = date('m', strtotime($date));

echo "Day: " . $day . "<br>";
echo "Month: " . $month;