0

I am getting the duration of a video like 9:55 or 00:13:51 . I want to add these values in a loop in php

I have tried like

    $t_duartion =0;
    foreach ($learn_detail->video_det as $video_det){
        $t_duartion += date("H:i:s",strtotime($video_det->duration));
    }

But the result is not coming. Its not coming as hh:mm:ss format. How to achieve this guys in php.

Any body idea ?

UI Dev
  • 689
  • 2
  • 9
  • 31
  • possible duplicate of [PHP Adding 15 minutes to Time value](http://stackoverflow.com/questions/20557059/php-adding-15-minutes-to-time-value) – Halayem Anis Jan 31 '15 at 09:09

2 Answers2

1

According to your logic your trying to add 00:13:00 and 09:14:53 etc which is wrong.try this:

    foreach ($learn_detail->video_det as $video_det){
        $t_duartion += strtotime($video_det->duration);
    }
$t_duartion = date("H:i:s",$t_duartion);
Nishanth Matha
  • 5,993
  • 2
  • 19
  • 28
1

Add all the durations together in seconds first and then use date().

Example:

$t_duartion = 0; // Typo in variable name btw.

foreach ( $learn_detail->video_det as $video_det ) {
    // Add duration of current video in seconds to total count.
    $t_duartion += strtotime( $video_det->duration );
}

// Convert total seconds to hh:mm:ss format.
$time = date( 'H:i:s', $t_duartion );
Nathan Dawson
  • 18,138
  • 3
  • 52
  • 58