What best practices should be followed when storing and retrieving date/time information in a database using PHP?

When storing date/time information in a database using PHP, it is recommended to store dates in the database using the DATETIME data type to ensure accuracy and consistency. When retrieving date/time information from the database, it is important to use PHP's DateTime class to handle and format the dates properly.

// Storing date/time information in the database
$date = new DateTime();
$datetime = $date->format('Y-m-d H:i:s');
$query = "INSERT INTO table_name (datetime_column) VALUES ('$datetime')";
// Execute the query

// Retrieving date/time information from the database
$query = "SELECT datetime_column FROM table_name";
// Execute the query
$result = // fetch the result
$date = new DateTime($result['datetime_column']);
$formatted_date = $date->format('Y-m-d H:i:s');
echo $formatted_date;