Solved

Adding two sets of minutes together php

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 is …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

856 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