Solved

Insert Duration from Users Form

Posted on 2009-07-01
3
223 Views
Last Modified: 2012-05-07
This can't be that hard but after hours of reading and testing I've got very comfused and a little angry with my PC, I know it's not its fault really....

What I need is a way to insert the duration time from two input text boxes named/ID'ed TripStart and TripEnd, when the form is posted all I need is a calculation of time passed from TripStart and TripEnd.

i.e. user enters 10:30 and 12:30, I need both those added to database (can do this ok), but also in another field called Duration the results of the calculation, 2:00. should the time be entered 23:30 and 03:30 the value added should be 4:00.

Any help would be good, pretty good at the database side of things, its the PHP that is killing me, lol...

High points as need a fast and clear to follow method, willing to increase points if needed.
0
Comment
Question by:Dan-LL
[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
3 Comments
 
LVL 5

Accepted Solution

by:
yauhing earned 500 total points
ID: 24756477
Please find below example:
<?
function calc($start, $end){
	$a = split(":", $start);
	$b = split(":", $end);
	
	$start_min = $a[0] * 60 + $a[1];
	$end_min = $b[0] * 60 + $b[1];
	
	if ($end_min < $start_min)	$end_min += (24 * 60); 
	
	$diff_min = $end_min - $start_min;
	return intval($diff_min / 60).":". substr("0".($diff_min % 60), -2);
}
 
$TripStart = "23:30";
$TripEnd = "03:30";
 
echo calc($TripStart, $TripEnd);
?>

Open in new window

0
 
LVL 1

Author Comment

by:Dan-LL
ID: 24756752
Many Many Thanks for that, It works fantastic, I am very slightly over the moon, thanks once again.
0
 
LVL 1

Author Closing Comment

by:Dan-LL
ID: 31598857
Thanks so much, gave you the bonus points as promised for a fast and in detailed reply... Thank You
0

Featured Post

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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.
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 …

707 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