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:...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 ? . |
|
|||
|
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 |
|
|||
|
<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 . |
|
|||
|
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 |
|
|||
|
<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 . |
|
|||
|
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 ================== |
|
|||
|
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! |