tags:

views:

59

answers:

6

I am having the blog,

Regularly i post some fun thing,

my user response for that,

i maintain the timestamps for response time,

How to display the something like this

2010-02-09 1hour before, if reply is just 1hour old

2010-02-09 20hour before ,if reply is just 20hour old

2010-02-08 yesterday ,if reply is just 1day old

2010-02-04 17:20, if reply is couple of days before

am maintain the timestamp in db ,for example my timestamp is 1265709142

Tell me how to this with php,

+1  A: 

There is a javascript library for that: http://tpgblog.com/cutetime/ Just print your dates in a certain format and add the js library to your page. Done.

ZeissS
+2  A: 

I'm sure there are PHP based approaches for this and I'm interested to see some, but there is also a JQuery based plugin named Pretty Date. I think Stack Overflow uses that.

It depends of course on JavaScript being activated in the user's browser, but degrades gracefully when JavaScript is off. Also, in search engines, the real date is indexed and not the formatted date - a small but nice plus.

Pekka
+1  A: 

The best thing is to format the time according to ISO, e.g. 2008-07-17T09:24:17Z

<?php 
  $DateOfRequest = date("Y-m-dTH:i:s", $timestamp); 
?> 

Then, use http://timeago.yarp.com/ to inject format strings like "2 hours ago" or so.

mnemosyn
+3  A: 
$d = time() - $timestamp;
if ($d < 60)
    return $d." second".(($d==1)?'':'s')." ago";
else
{
    $d = floor($d / 60);
    if($d < 60)
        return $d." minute".(($d==1)?'':'s')." ago";
    else
    {
        $d = floor($d / 60);
        if($d < 24)
            return $d." hour".(($d==1)?'':'s')." ago";
        else
        {
            $d = floor($d / 24);
            if($d < 7)
                return $d." day".(($d==1)?'':'s')." ago";
            else
            {
                $d = floor($d / 7);
                if($d < 4)
                    return $d." week".(($d==1)?'':'s')." ago";
            }//Week
        }//Day
    }//Hour
}//Minute
Wil
For $time , what i have to parse...timestamp means current time stamp?
Bharanikumar
Hi all am loking solution in php
Bharanikumar
How to find timestamp is two days old, How much timestamp for one day
Bharanikumar
Sorry $time should be time()
Wil
A: 

WHAT I EXPECTED HERE

BUT IF THE 2 DAYS PAST, THEN I WANT TO DISPLAY DATEE AND TIME

Bharanikumar
A: 

my prob solution link

Bharanikumar