Are there any best practices recommended for extracting the year from a date string in PHP to ensure accurate results?

When extracting the year from a date string in PHP, it is important to ensure that the date format is consistent to avoid any errors. One recommended best practice is to use the date() function along with the strtotime() function to extract the year from the date string accurately.

$dateString = "2022-09-15";
$year = date('Y', strtotime($dateString));
echo $year; // Output: 2022