What are common methods for adding dates and times in PHP, and what are the potential pitfalls associated with each method?
When working with dates and times in PHP, common methods for adding dates include using the `strtotime()` function or the `DateTime` class. However, it's important to be aware of potential pitfalls such as timezone discrepancies and unexpected results when adding dates with different formats.
// Using strtotime() to add days to a date
$date = "2022-01-01";
$days_to_add = 7;
$new_date = date('Y-m-d', strtotime($date . ' + ' . $days_to_add . ' days'));
echo $new_date;
```
```php
// Using DateTime class to add days to a date
$date = new DateTime("2022-01-01");
$days_to_add = new DateInterval('P7D');
$date->add($days_to_add);
echo $date->format('Y-m-d');