Re: [PHP] Seconds to minutes
Ahhh - that works a treat! First time I've seen the floor command in action. Thanks Jonathon. Still more lines of code than I'd like, but obviously its not that easy to do! Best Regards Bob Irwin Server Admin & Web Programmer Planet Netcom - Original Message - From: "Jonathan Sharp" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Cc: "'Matt'" <[EMAIL PROTECTED]>; "'Bob Irwin'" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Wednesday, November 20, 2002 12:41 PM Subject: Re: [PHP] Seconds to minutes > i'll just throw my code in here while we're at it... > > $seconds = 3600*5 + (60 * 10) + 45; > > $hours = floor( $seconds / 3600 ); > $mins = floor( ($seconds % 3600) / 60 ); > $seconds = floor( ($seconds % 60) ); > > echo "Hours: $hours\nMins: $mins\nSeconds: $seconds\n"; > > -js > > > John W. Holmes wrote: > >>You can do something like this: > >> >> $seconds = 265; > >> $time = date('i s',$seconds); > >> $minSecs = explode(' ',$time); > >> echo "{$minSecs[0]} minutes and {$minSecs[1]} seconds\n"; > >>?> > > > > > > That doesn't work for anything over 3599 seconds, though... > > > > ---John Holmes... > > > > > > > > > > > Scanned by PeNiCillin http://safe-t-net.pnc.com.au/ > Scanned by PeNiCillin http://safe-t-net.pnc.com.au/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Seconds to minutes
i'll just throw my code in here while we're at it... $seconds = 3600*5 + (60 * 10) + 45; $hours = floor( $seconds / 3600 ); $mins = floor( ($seconds % 3600) / 60 ); $seconds = floor( ($seconds % 60) ); echo "Hours: $hours\nMins: $mins\nSeconds: $seconds\n"; -js John W. Holmes wrote: >>You can do something like this: >>> $seconds = 265; >> $time = date('i s',$seconds); >> $minSecs = explode(' ',$time); >> echo "{$minSecs[0]} minutes and {$minSecs[1]} seconds\n"; >>?> > > > That doesn't work for anything over 3599 seconds, though... > > ---John Holmes... > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Seconds to minutes
On Wed, 20 Nov 2002, Bob Irwin wrote: > Its seems far more reliable than what I am using (dividing by 60 for > minutes, 3600 for hours and doing rounding, exploding if its not a round > number etc). > > Its only for measuring short times, so Matt's suggestion should work ok. > Ideally though, because it will crop up from time to time, it'd be the go to > do it right the first time. > > Anyone else know of a better way? How about something like this, given $seconds containing the number of seconds? $secs = $seconds; $hours = $secs / 3600; $secs %= 3600; $mins = $secs / 60; $mins %= 60; $out = sprintf ("%d hour%s, %d minute%s, %d second%s", $hours, ($hours == 1 ? '' : 's'), $mins, ($mins == 1 ? '' : 's'), $secs, ($secs == 1 ? '' : 's')); -- Morgan Hughes C programmer and highly caffeinated mammal. [EMAIL PROTECTED] ICQ: 79293356 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Seconds to minutes
Bob, Instead of dividing, use modulus to get the exact number of remaining seconds, and then determine the minutes from that. Here is some code that I've quickly adapted from another language I use, to take the total minutes, and convert it to "hours:minutes" display. $totalmins = 193; $showmins = $totalmins%60; $showhrs = ($totalmins-$showmins)/60; echo $showhrs.":".$showmins; I haven't tested this, but it might give you a start. The same concept would apply to converting seconds to minutes... Peter At 12:16 PM 11/20/2002 +1100, Bob Irwin wrote: Its seems far more reliable than what I am using (dividing by 60 for minutes, 3600 for hours and doing rounding, exploding if its not a round number etc). Its only for measuring short times, so Matt's suggestion should work ok. Ideally though, because it will crop up from time to time, it'd be the go to do it right the first time. Anyone else know of a better way? Best Regards Bob Irwin Server Admin & Web Programmer Planet Netcom - Original Message - From: "John W. Holmes" <[EMAIL PROTECTED]> To: "'Matt'" <[EMAIL PROTECTED]>; "'Bob Irwin'" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Wednesday, November 20, 2002 12:09 PM Subject: RE: [PHP] Seconds to minutes > > You can do something like this: > > > $seconds = 265; > > $time = date('i s',$seconds); > > $minSecs = explode(' ',$time); > > echo "{$minSecs[0]} minutes and {$minSecs[1]} seconds\n"; > > ?> > > That doesn't work for anything over 3599 seconds, though... > > ---John Holmes... > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > Scanned by PeNiCillin http://safe-t-net.pnc.com.au/ > > Scanned by PeNiCillin http://safe-t-net.pnc.com.au/ > Scanned by PeNiCillin http://safe-t-net.pnc.com.au/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php - - - - - - - - - - - - - - - - - - - - - Fourth Realm Solutions [EMAIL PROTECTED] http://www.fourthrealm.com Tel: 519-739-1652 - - - - - - - - - - - - - - - - - - - - - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Seconds to minutes
Its seems far more reliable than what I am using (dividing by 60 for minutes, 3600 for hours and doing rounding, exploding if its not a round number etc). Its only for measuring short times, so Matt's suggestion should work ok. Ideally though, because it will crop up from time to time, it'd be the go to do it right the first time. Anyone else know of a better way? Best Regards Bob Irwin Server Admin & Web Programmer Planet Netcom - Original Message - From: "John W. Holmes" <[EMAIL PROTECTED]> To: "'Matt'" <[EMAIL PROTECTED]>; "'Bob Irwin'" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Wednesday, November 20, 2002 12:09 PM Subject: RE: [PHP] Seconds to minutes > > You can do something like this: > > > $seconds = 265; > > $time = date('i s',$seconds); > > $minSecs = explode(' ',$time); > > echo "{$minSecs[0]} minutes and {$minSecs[1]} seconds\n"; > > ?> > > That doesn't work for anything over 3599 seconds, though... > > ---John Holmes... > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > Scanned by PeNiCillin http://safe-t-net.pnc.com.au/ > > Scanned by PeNiCillin http://safe-t-net.pnc.com.au/ > Scanned by PeNiCillin http://safe-t-net.pnc.com.au/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Seconds to minutes
> You can do something like this: > $seconds = 265; > $time = date('i s',$seconds); > $minSecs = explode(' ',$time); > echo "{$minSecs[0]} minutes and {$minSecs[1]} seconds\n"; > ?> That doesn't work for anything over 3599 seconds, though... ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Seconds to minutes
>From: "Bob Irwin" <[EMAIL PROTECTED]> > Sent: Tuesday, November 19, 2002 7:27 PM >Subject: [PHP] Seconds to minutes > At the moment, I'm using quite a few lines of code to convert seconds to > minutes and hours. I'm thinking, surely I'm missing something really > simple! Is there a PHP function that converts seconds to minutes? Or is it > a 4 or 5 (and not always that accurate) lines of code? You can do something like this: \n"; ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Seconds to minutes
Hey Guys, At the moment, I'm using quite a few lines of code to convert seconds to minutes and hours. I'm thinking, surely I'm missing something really simple! Is there a PHP function that converts seconds to minutes? Or is it a 4 or 5 (and not always that accurate) lines of code? Any ideas or input would be appreciated. Best Regards Bob Irwin Server Admin & Web Programmer Planet Netcom Scanned by PeNiCillin http://safe-t-net.pnc.com.au/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php