Solved

Adding two sets of minutes together php

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

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 …
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …

749 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