Solved

Adding two sets of minutes together php

Posted on 2012-03-30
2
201 Views
Last Modified: 2012-03-30
I'm pulling the length of a video out of a database, that is in the format 00:00:00

I then want to add 15 minutes to that time to allot for total time required.  I can't quite seem to get there.

$videotime = mysql_result($res2,$b, 0);
$quiztime = "00:15:00";


                  echo "Video time is: " . $videotime . '<br />';
                  echo "Quiz length is: " . $quiztime . '<br />';
            
                  // $duration = mktime ($videotime + $quiztime);
                  // $duration = date("i:s", $duration);
                  
                  $hours_diff = ((strtotime($videotime)) + (strtotime($quiztime)));
                  echo  date('h:i:s', $hours_diff)." Minutes";
            
                  echo '<br /><br />';
0
Comment
Question by:t3chguy
2 Comments
 
LVL 21

Accepted Solution

by:
Kim Walker earned 325 total points
ID: 37789220
strtotime returns the time relative to today. So "00:15:00" is equal to March 30, 2012 12:15:00am and your video length would be equally that time past midnight this morning. You will need to eliminate today's date in order to add the additional 15 minutes. You also need to format your date for a 24 hour clock.
$videotime = "00:05:00";
$quiztime = "00:15:00";
$zerohour = "00:00:00";

echo "Video time is: " . date('m d, Y H:i:s',strtotime($videotime) ) . '<br />';
echo "Quiz length is: " . date('m d, Y H:i:s',strtotime($quiztime) ) . '<br />';
echo "Zero hour is: " . date('m d, Y H:i:s',strtotime($zerohour) ) . '<br />';

$hours_diff = ((strtotime($videotime) ) + (strtotime($quiztime)-strtotime($zerohour) ));
echo  date('H:i:s', $hours_diff)." Minutes";

Open in new window

This will not work if your video length should ever be more than 23:45:00. But I doubt that will be a problem.
0
 
LVL 1

Author Closing Comment

by:t3chguy
ID: 37789237
Perfect!  Thank you for the explanation and the code!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now