How can PHP be used to format and display time values from a MySQL database in a user-friendly way?

When retrieving time values from a MySQL database, they are often in a format that is not user-friendly. To format and display these time values in a more readable way, you can use PHP's date() function along with strtotime() to convert the MySQL time value into a user-friendly format. This can be done by fetching the time value from the database, converting it to a Unix timestamp using strtotime(), and then formatting it using date().

// Retrieve time value from MySQL database
$timeFromDatabase = "2022-01-15 14:30:00";

// Convert MySQL time value to Unix timestamp
$timestamp = strtotime($timeFromDatabase);

// Format the timestamp into a user-friendly format
$formattedTime = date("F j, Y, g:i a", $timestamp);

// Display the formatted time value
echo $formattedTime;