[SOLVED] Times

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

[SOLVED] Times

Post 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 ?
Last edited by Dale on Sat May 28, 2005 11:53 am, edited 1 time in total.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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?
R0d Longfella
Forum Newbie
Posts: 20
Joined: Fri Apr 08, 2005 7:17 am

Post by R0d Longfella »

Code: Select all

<?php
printf ("%d minutes, %d Seconds", $data_number % 60, $data_number / 60);
?>
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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);
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post 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?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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?
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

C'mon man.. its not complicated, very simple math. :wink:
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post by Dale »

Jcart wrote:C'mon man.. its not complicated, very simple math. :wink:
Worked it :)

Thanks.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I knew you had it in you :) Good job.
Post Reply