# How to calculate the running time

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
The start and end times for a tv show or film .

17:50
18:30

40 minutes running time

23:50
00:30

40 minutes running time

23:50
01:40

110 minutes running time

While i could write the code in a luddite type of fashion and it would
work fine and stuff - is there a one or two line solution that would do
the same job ? .

## Re: How to calculate the running time

Krustov napisał(a):

echo (strtotime("18:30")-strtotime("17:50"))/60;
echo (strtotime("+1 days 1:40")-strtotime("23:50"))/60;
at least I don't know any better solution :)

--
Wiktor Walc
http://phpfreelancer.net

## Re: How to calculate the running time

<comp.lang.php>
<iktorn>
<Fri, 23 Mar 2007 20:51:52 +0100>

At least you gave it crack :-)

18:05
21:10

23:20
01:15

etc

The ideal solution would be one that takes two unknown values to produce
a end result value running time like 100 minutes .

## Re: How to calculate the running time

Krustov napisał(a):

function f(\$start,\$end){
return (\$start>\$end?(strtotime("+1 day
".\$end)-strtotime(\$start)):(strtotime(\$end)-strtotime(\$start)))/60;
}

;)

--
Wiktor Walc
http://phpfreelancer.net

## Re: How to calculate the running time

<comp.lang.php>
<iktorn>
<Fri, 23 Mar 2007 21:58:38 +0100>

That does the job fine - nice one dude .

## Re: How to calculate the running time

iktorn wrote:

Or to put everything in one statement, perhaps

echo ((strtotime("+1 days 1:40")-strtotime("23:50"))/60) % (24*60*60);

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

## Re: How to calculate the running time

Krustov wrote:

<?php

\$start = '23:50';
\$end   = '01:40';

list(\$start_h, \$start_m) = explode(':', \$start);
\$start = (60 * \$start_h)  +  \$start_m;

list(\$end_h, \$end_m ) = explode(':', \$end);
\$end = (60 * \$end_h)  +  \$end_m;

\$length = \$end - \$start;
if (\$length < 0)
\$length += 1440;

echo "Length is \$length minutes.\n";

?>

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!