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 ?

1

2 Answers 2

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 );
Sign up to request clarification or add additional context in comments.

Comments

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.