What potential issues can arise when using strtotime() to format dates in PHP?

One potential issue that can arise when using strtotime() to format dates in PHP is that it may not handle all date formats correctly, leading to unexpected results. To solve this, it is recommended to use DateTime::createFromFormat() instead, which allows you to specify the exact format of the date string.

$dateString = "2022-12-31";
$date = DateTime::createFromFormat('Y-m-d', $dateString);
$formattedDate = $date->format('Y-m-d');
echo $formattedDate;