How can one ensure that the date format being used is valid for strtotime() in PHP?

When using strtotime() in PHP, it is important to ensure that the date format being used is valid. One way to do this is by using the date() function to format the date string in a way that strtotime() can understand. By formatting the date string correctly, we can avoid any errors or unexpected results when using strtotime().

$dateString = '2022-12-31';
$timestamp = strtotime(date('Y-m-d', strtotime($dateString)));
echo date('Y-m-d', $timestamp);