What are some common mistakes to avoid when working with time calculations in PHP?

One common mistake when working with time calculations in PHP is not considering time zones. Always ensure that you are working with the correct time zone to avoid discrepancies in your calculations.

// Set the default time zone to use in your calculations
date_default_timezone_set('America/New_York');

// Example of calculating the difference between two dates
$date1 = new DateTime('2022-01-01 00:00:00');
$date2 = new DateTime('2022-01-02 12:00:00');

$interval = $date1->diff($date2);
echo $interval->format('%d days %h hours %i minutes');