Jump to content

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...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.