In PHP, what are some best practices for handling date calculations and ensuring accurate results when adding durations to dates?

When adding durations to dates in PHP, it is important to use the DateTime class to ensure accurate results, especially when considering factors like timezones and daylight saving time. By using the DateTime class and its methods for date calculations, you can handle date arithmetic correctly and avoid common pitfalls that may arise when manipulating dates manually.

// Create a DateTime object for the initial date
$date = new DateTime('2022-01-01');

// Add a duration of 1 day to the date
$date->add(new DateInterval('P1D'));

// Output the result in the desired format
echo $date->format('Y-m-d');