Solved

Adding two sets of minutes together php

Posted on 2012-03-30
2
202 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 22

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses four methods for overlaying images in a container on a web page
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 …

895 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

13 Experts available now in Live!

Get 1:1 Help Now