In what ways can you convert and format dates retrieved from a database into a different format using PHP?

When retrieving dates from a database in PHP, you may need to convert and format them into a different format for display or manipulation. One way to achieve this is by using the date() function along with strtotime() to convert the retrieved date string into a Unix timestamp and then format it as needed using the date() function with the desired format specifier.

// Retrieve date from database
$dateFromDatabase = "2022-01-15";

// Convert date to Unix timestamp and format it
$formattedDate = date("Y-m-d", strtotime($dateFromDatabase));

// Output the formatted date
echo $formattedDate;