How can PHP be used to format dates for insertion into a database?

When inserting dates into a database using PHP, it's important to format the date correctly to ensure it is stored accurately. One common way to format dates for insertion into a database is by using the `date()` function in PHP to convert the date into the desired format. This function allows you to specify the format of the date string, such as 'Y-m-d H:i:s' for a date and time format compatible with most databases.

$date = '2022-01-15 14:30:00'; // Example date string
$formatted_date = date('Y-m-d H:i:s', strtotime($date));
// $formatted_date now contains '2022-01-15 14:30:00' in the correct format for database insertion