What is the best practice for converting dates in PHP without altering the database format?

When converting dates in PHP without altering the database format, it's important to ensure that the date is properly formatted for display or manipulation in PHP. One common approach is to use PHP's DateTime class to convert the date from the database format to a desired format. This allows you to manipulate the date object as needed without changing the underlying database format.

// Assuming $dbDate is the date fetched from the database in 'Y-m-d' format
$dbDate = '2022-01-15';

// Convert the database date to desired format 'd/m/Y'
$dateObj = DateTime::createFromFormat('Y-m-d', $dbDate);
$convertedDate = $dateObj->format('d/m/Y');

echo $convertedDate; // Output: 15/01/2022