How to calculate the running time

This is a discussion on How to calculate the running time within the PHP Language forums, part of the PHP Programming Forums category; The start and end times for a tv show or film . 17:50 18:30 40 minutes running time 23:...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-23-2007
Krustov
 
Posts: n/a
Default 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 ? .
Reply With Quote
  #2 (permalink)  
Old 03-23-2007
iktorn
 
Posts: n/a
Default Re: How to calculate the running time

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
Reply With Quote
  #3 (permalink)  
Old 03-23-2007
Krustov
 
Posts: n/a
Default Re: How to calculate the running time

<comp.lang.php>
<iktorn>
<Fri, 23 Mar 2007 20:51:52 +0100>
<eu1b3e$85c$1@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 .
Reply With Quote
  #4 (permalink)  
Old 03-23-2007
iktorn
 
Posts: n/a
Default Re: How to calculate the running time

Krustov napisał(a):
> <comp.lang.php>
> <iktorn>
> <Fri, 23 Mar 2007 20:51:52 +0100>
> <eu1b3e$85c$1@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
Reply With Quote
  #5 (permalink)  
Old 03-23-2007
Krustov
 
Posts: n/a
Default Re: How to calculate the running time

<comp.lang.php>
<iktorn>
<Fri, 23 Mar 2007 21:58:38 +0100>
<eu1f0k$ghm$1@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 .

Reply With Quote
  #6 (permalink)  
Old 03-24-2007
Jerry Stuckle
 
Posts: n/a
Default Re: How to calculate the running time

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.
jstucklex@attglobal.net
==================
Reply With Quote
  #7 (permalink)  
Old 03-24-2007
Toby A Inkster
 
Posts: n/a
Default Re: How to calculate the running time

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!
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:19 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0