How can date and time formatting be effectively managed in PHP when retrieving and displaying data from a MySQL database?

When retrieving date and time data from a MySQL database in PHP, it's important to format it correctly for display. This can be achieved by using the date() function in PHP to format the date and time according to your desired format. Additionally, you can use the strtotime() function to convert the MySQL timestamp to a Unix timestamp before formatting it.

// Retrieve date and time data from MySQL database
$timestamp = $row['timestamp'];

// Convert MySQL timestamp to Unix timestamp
$unix_timestamp = strtotime($timestamp);

// Format the date and time
$formatted_date = date('Y-m-d H:i:s', $unix_timestamp);

// Display the formatted date and time
echo $formatted_date;