$php_mysql$ Posted July 12, 2011 Share Posted July 12, 2011 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/>"; } Link to comment https://forums.phpfreaks.com/topic/241779-how-to-show-post-time-like-posted-few-seconds-ago/ Share on other sites More sharing options...
$php_mysql$ Posted July 12, 2011 Author Share Posted July 12, 2011 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; } ?> Link to comment https://forums.phpfreaks.com/topic/241779-how-to-show-post-time-like-posted-few-seconds-ago/#findComment-1241720 Share on other sites More sharing options...
$php_mysql$ Posted July 13, 2011 Author Share Posted July 13, 2011 any help? Link to comment https://forums.phpfreaks.com/topic/241779-how-to-show-post-time-like-posted-few-seconds-ago/#findComment-1242143 Share on other sites More sharing options...
AyKay47 Posted August 9, 2011 Share Posted August 9, 2011 nope Link to comment https://forums.phpfreaks.com/topic/241779-how-to-show-post-time-like-posted-few-seconds-ago/#findComment-1254901 Share on other sites More sharing options...
the182guy Posted August 9, 2011 Share Posted August 9, 2011 The one you have can be used like foreach($userPost as $p){ $postTime = ago($p['postTime']); echo "Post: ".$p['postTitle'].", ".$postTime."<br/>"; } There is another one here: http://www.php.net/manual/en/function.time.php#91864 Link to comment https://forums.phpfreaks.com/topic/241779-how-to-show-post-time-like-posted-few-seconds-ago/#findComment-1254910 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.