How can PHP's DateTime::diff function be effectively used to calculate time differences and intervals in a database context?

When working with dates and times in a database context, PHP's DateTime::diff function can be effectively used to calculate time differences and intervals between two DateTime objects. This can be useful for calculating the duration between two timestamps, determining the age of a record, or calculating the time elapsed since a specific event.

// Create two DateTime objects representing the start and end timestamps
$start = new DateTime('2022-01-01 12:00:00');
$end = new DateTime('2022-01-02 08:30:00');

// Calculate the time difference between the two DateTime objects
$interval = $start->diff($end);

// Output the time difference in a readable format
echo $interval->format('%d days, %h hours, %i minutes');