Summing time in DateTime() objects
<p>I have an array of DateTime() objects in which I store some time duration (like "H:i")
How can I sum all elements in this array to get total time duration? </p>

<p>And it's also should be taken into account, that if total time duration is grater that 23:59, I have to be able to get nubmer of days.</p>

<p>is this possible?</p>

<p>I was trying to do like this:</p>

<pre><code>$duration = new DateTime('00:00');

foreach($routes as $route) {
   $arrival_time = new DateTime();
   $arrival_time-&gt;setTimestamp($route-&gt;arrival_time);

   $departure_time = new DateTime();
   $departure_time-&gt;setTimestamp($route-&gt;departure_time);

   $leg_duration = $arrival_time-&gt;diff($departure_time);
   $duration-&gt;add($leg_duration);
}
</code></pre>

<p>but in <code>$duration</code> I got wrong time.</p>

<p><strong>P.S.</strong></p>

<p>Using <code>$duration-&gt;add($leg_duration);</code> I got subtracted from <code>"24:00"</code> time, why?
For example if <code>$leg_duration = new DateTime('02:10');</code> the result will be <code>"21:50"</code>.</p>

<p><code>$duration-&gt;sub($leg_duration);</code> add time to <code>"24:00"</code></p>

<p>Is this right?</p>
