Originally posted by psycorpse
I am building a forum and what I am tring to do is show when the last post was. here is what I can do. I can pull the epoch time out of the database and subtrack that from time() and get a small number. How ever I dont know how to format it to show.
1day 2hrs 3mins. Some will come to a 2 digit outcome up to a 6 digit outcome. From what I under stand this 123456 = 1 day 2 hours 34 mins 56 secs. if it was always a 6 digit I could probably use explode(). if anyone has any ideas please post.
Hi,
I'm not sure I understood you, but if you substract two unix timestamps you get number of seconds between these two times. All you have to do is to convert these SECONDS into format you need. For example you can do something like this:
function secondsToHours($totalSeconds) {
$seconds = (int)($totalSeconds % 60);
if ($seconds < 10) $seconds = '0' . $seconds;
$minutes = (int)(($totalSeconds / 60) % 60);
if ($minutes < 10) $minutes = '0' . $minutes;
$hours = (int)($totalSeconds / 3600);
if ($hours < 10) $hours = '0' . $hours;
return $hours . ':' . $minutes . ':' . $seconds;
}
Regards,
Dejan