Topic: Time Stamp in the format "3 days ago" or "2 hours ago"

I find the above method much more useful and informative than 12.16.2008 15:35

I found the following code on php.net, can this be put to use somehow:

<?php
    function ago($timestamp){
        $difference = time() - $timestamp;

        if($difference < 60)
            return $difference." seconds ago";
        else{
            $difference = round($difference / 60);
            if($difference < 60)
                return $difference." minutes ago";
            else{
                $difference = round($difference / 60);
                if($difference < 24)
                    return $difference." hours ago";
                else{
                    $difference = round($difference / 24);
                    if($difference < 7)
                        return $difference." days ago";
                    else{
                        $difference = round($difference / 7);
                        return $difference." weeks ago";
                    }
                }
            }
        }
    }
?>

Re: Time Stamp in the format "3 days ago" or "2 hours ago"

Anyone know how to achieve the above?

Re: Time Stamp in the format "3 days ago" or "2 hours ago"

Replace Lines 390 - 397 on 'include/functions.php' with this.

4

Re: Time Stamp in the format "3 days ago" or "2 hours ago"

Doesn't work for me. I get

Notice: Undefined variable: d in /home/forum/include/functions.php on line 390

Re: Time Stamp in the format "3 days ago" or "2 hours ago"

Replace variable $d with $timestamp in the code

Re: Time Stamp in the format "3 days ago" or "2 hours ago"

Oh... I forgot a line from the code! I edited the code. It should work now.

Re: Time Stamp in the format "3 days ago" or "2 hours ago"

It doesn't work for me.
I suspect I'm pasting it in the wrong place.
Garciat, would you mind pasting the code here that I should delete in place of your code?
Just so I know I'm swapping the right code.
I hope that's ok! Nearly there now smile smile

Re: Time Stamp in the format "3 days ago" or "2 hours ago"

            $base = gmdate('Y-m-d', $timestamp);
            $today = gmdate('Y-m-d', $now + $diff);
            $yesterday = gmdate('Y-m-d', $now + $diff - 86400);

            if ($base == $today)
                $formatted_time = $lang_common['Today'];
            else if ($base == $yesterday)
                $formatted_time = $lang_common['Yesterday'];

Re: Time Stamp in the format "3 days ago" or "2 hours ago"

hmmm, I get:

Notice: Undefined variable: time in /home/mark4321/public_html/forum/include/functions.php on line 390

Re: Time Stamp in the format "3 days ago" or "2 hours ago"

Any further clues with this Garciat?

11

Re: Time Stamp in the format "3 days ago" or "2 hours ago"

See this post http://punbb.informer.com/forums/topic/ … ith-topic/ it uses the time thing