467,907 Members | 1,407 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,907 developers. It's quick & easy.

How to calculate the running time

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 ? .
Mar 23 '07 #1
  • viewed: 2879
Share:
6 Replies
Krustov napisał(a):
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 ? .
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
Mar 23 '07 #2
<comp.lang.php>
<iktorn>
<Fri, 23 Mar 2007 20:51:52 +0100>
<eu**********@news.task.gda.pl>
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 :)
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 .
Mar 23 '07 #3
Krustov napisał(a):
<comp.lang.php>
<iktorn>
<Fri, 23 Mar 2007 20:51:52 +0100>
<eu**********@news.task.gda.pl>
>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 :)

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 .
function f($start,$end){
return ($start>$end?(strtotime("+1 day
".$end)-strtotime($start)):(strtotime($end)-strtotime($start)))/60;
}

;)

--
Wiktor Walc
http://phpfreelancer.net
Mar 23 '07 #4
<comp.lang.php>
<iktorn>
<Fri, 23 Mar 2007 21:58:38 +0100>
<eu**********@news.task.gda.pl>
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 .

function f($start,$end){
return ($start>$end?(strtotime("+1 day
".$end)-strtotime($start)):(strtotime($end)-strtotime($start)))/60;
}
That does the job fine - nice one dude .

Mar 23 '07 #5
iktorn wrote:
Krustov napisał(a):
>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 ? .

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 :)
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.
js*******@attglobal.net
==================
Mar 23 '07 #6
Krustov wrote:
23:50
01:40

110 minutes running time
<?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!
Mar 24 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by shrishjain | last post: by
3 posts views Thread by SSG | last post: by
4 posts views Thread by Rajeev | last post: by
reply views Thread by Rajeev | last post: by
20 posts views Thread by upperclass | last post: by
2 posts views Thread by upperclass | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.