Page 1 of 1

backwords counting

Posted: Sat Aug 21, 2004 12:14 am
by pinehead18
Ok, lets pretend that i have a lil forum on my website. (i really do) and whenever someone posts a new topic or reply mysql creates a time stamp that, well lets say looks like this "1092791237" and i want to write a little script that says how many min or hour ago that the reply or new topic was posted.

How might i go about that?

Thank you
Anthony

Posted: Sat Aug 21, 2004 12:54 am
by litebearer
Since a timestamp is seconds,
[QUOTE}
seconds_elapsed = timestamp_now - timestamp_then
minutes_elapsed = floor(seconds_elapsed / 60)
[/QUOTE]
and so on

Lite...

Posted: Sat Aug 21, 2004 1:21 am
by pinehead18
Now what if it has been more than 60 min and i want to say 1 hour 15 min.

How would i go about that calculation?

Thank you for your help.

Anthony

Posted: Sat Aug 21, 2004 1:24 am
by feyd
his "code" says minutes elapsed.. not hours..

Posted: Sat Aug 21, 2004 1:31 am
by pinehead18
Right, i was just wondering if i could use the minutes elapsed and create hours and minutes. LIke 5 hours 4 min ago

Posted: Sat Aug 21, 2004 1:46 am
by feyd
you can, however, you will need additional math for each component then.

Posted: Sat Aug 21, 2004 1:49 am
by litebearer
this is simply the thought process (using MODULUS etc will shorten the coding)

(read psuedo code)

Code: Select all

hours = floor(seconds_elasped / (60*60))
    seconds_left_over = seconds_elapsed - (hours*60*60)
minutes = floor(seconds_left_over/60)
seconds = seconds_left_over - (minutes*60)
elapsed_time = hours:minutes:seconds