0

I am trying to add two DateInterval objects together. The DateInterval->add() method does not exist, but I'd like to do something like this:

$interval1 = new DateInterval('PT2H47M13S');
$interval2 = new DateInterval('PT4H19M22S');

$interval1->add($interval2);

echo $interval1->format('%hh %im %ss');

Results in: 7h 6m 35s

I understand I can create a new class that extends the DateInterval class and write the method for adding the 2 together myself. But, the DateInterval objects I am using are coming from the return value of date_diff(). So unless there is someway to convert the DateInterval object cleanly into the extended class, I'm not sure what to do.

user2391788
  • 93
  • 1
  • 5
  • 1
    I think this may already be what you're looking for: http://stackoverflow.com/questions/11556731/how-we-can-add-two-date-intervals-in-php – Inukshuk Dec 31 '13 at 22:11
  • That's exactly what I was looking for. I didn't find that in my searches. Thank you! – user2391788 Dec 31 '13 at 22:38

0 Answers0