What are some common methods in PHP to convert a MySQL DATE format (yyyy-mm-dd) into separate day, year, and month components?

When working with dates stored in MySQL in the format yyyy-mm-dd, you may need to extract the day, month, and year components separately for further processing or display. One common method to achieve this in PHP is to use the date_parse() function to parse the date string into an associative array containing individual components such as day, month, and year.

$date = "2022-10-15";
$dateComponents = date_parse($date);

$day = $dateComponents['day'];
$month = $dateComponents['month'];
$year = $dateComponents['year'];

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