Jump to content

how to show post time like, posted few seconds ago


$php_mysql$

Recommended Posts

friends how do i do that? i want to show posts time as

 

1. posted few seconds ago

2. posted about a minute ago

3. posted an hour ago

4. posted today

6. posted yesterday

7. posted on 2011-07-11 19:43:57

 

this is how i store the time `postTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,

 

display it like this

 

foreach($userPost as $p){
echo "Post: ".$p['postTitle'].", ".$p['postTime']."<br/>";
}

found this bit of coding but not sure how to use it with my codes could someone help?

 

<?php
function ago($timestamp){
   $difference = time() - $timestamp;
   $periods = array("second", "minute", "hour", "day", "week", "month", "years", "decade");
   $lengths = array("60","60","24","7","4.35","12","10");
   for($j = 0; $difference >= $lengths[$j]; $j++)
   $difference /= $lengths[$j];
   $difference = round($difference);
   if($difference != 1) $periods[$j].= "s";
   $text = "$difference $periods[$j] ago";
   return $text;
  }
?>

  • 4 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.