What are the potential pitfalls of using the explode function in PHP for date manipulation?

One potential pitfall of using the explode function in PHP for date manipulation is that it may not handle all date formats consistently, leading to unexpected results. To avoid this issue, it is recommended to use PHP's DateTime class, which provides a more robust and reliable way to manipulate dates.

$dateString = '2022-01-20';
$dateParts = explode('-', $dateString);
$date = new DateTime();
$date->setDate($dateParts[0], $dateParts[1], $dateParts[2]);
echo $date->format('Y-m-d'); // Output: 2022-01-20