Page 1 of 1

[SOLVED] Times

Posted: Sat May 28, 2005 8:37 am
by Dale
If i enter into the database a value 23 and get it to show on the page i can write:

Code: Select all

<?php
echo "$data_number seconds.";
?>
And that would show on the page 23 Seconds, however how do i make it so if i added a higher number like 65, how do i make it show something like 1 minute, 5 Seconds ?

Posted: Sat May 28, 2005 8:45 am
by shiznatix
well you could do some sort of see how many times 60 goes into 65 then take the remaning number and make that the seconds but why dont you just use date() and a DATE field in mysql?

Posted: Sat May 28, 2005 8:46 am
by R0d Longfella

Code: Select all

<?php
printf ("%d minutes, %d Seconds", $data_number % 60, $data_number / 60);
?>

Posted: Sat May 28, 2005 10:44 am
by JAM
R0d Longfella wrote:

Code: Select all

<?php
printf ("%d minutes, %d Seconds", $data_number % 60, $data_number / 60);
?>
Actually...

Code: Select all

printf ("%d minutes, %d Seconds", $data_number / 60, $data_number % 60);

Posted: Sat May 28, 2005 10:55 am
by Dale
JAM, what R0d Longfella said works fine for me. Now how would it work in the same context for doing that with hours too?

Posted: Sat May 28, 2005 11:07 am
by JAM

Code: Select all

<pre>
<?php
$data_number = 55;
printf ("%d minutes, %d Seconds", $data_number % 60, $data_number / 60);

$data_number = 65;
printf ("%d minutes, %d Seconds", $data_number % 60, $data_number / 60);
Results:

Code: Select all

55 minutes, 0 Seconds
5 minutes, 1 Seconds
See the error?

Posted: Sat May 28, 2005 11:14 am
by Dale
Ahh yeah i do, thats why i now want to know if adding an "hour" section in it would work just like that.

Posted: Sat May 28, 2005 11:39 am
by John Cartwright
C'mon man.. its not complicated, very simple math. :wink:

Posted: Sat May 28, 2005 11:47 am
by Dale
Jcart wrote:C'mon man.. its not complicated, very simple math. :wink:
Worked it :)

Thanks.

Posted: Sat May 28, 2005 11:50 am
by John Cartwright
I knew you had it in you :) Good job.