?
Solved

Adding two sets of minutes together php

Posted on 2012-03-30
2
Medium Priority
?
207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 22

Accepted Solution

by:
Kim Walker earned 1300 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

770 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