What are some alternative methods for adding durations of time in PHP, aside from using mktime()?
When adding durations of time in PHP, an alternative method to using mktime() is to utilize the DateTime class. This class provides a more object-oriented approach to working with dates and times, making it easier to perform operations such as adding durations. By creating DateTime objects for the start and end times, you can then use the add() method to add a specific duration to the start time.
$start = new DateTime('2022-01-01 12:00:00');
$duration = new DateInterval('PT1H30M'); // 1 hour and 30 minutes
$end = clone $start;
$end->add($duration);
echo $end->format('Y-m-d H:i:s'); // Output: 2022-01-01 13:30:00