This Forum has been archived there is no more new posts or threads ... use this link to report any abusive content
==> Report abusive content in this page <==
Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to create facebook or twitter like x-time ago date/time format in PHP?
10-01-2012, 09:57 AM
Post: #1
How to create facebook or twitter like x-time ago date/time format in PHP?
How to create facebook or twitter like x-time ago date/time format in PHP? Is there any built in function are available? Any help would be appreciated.

Ads

Find all posts by this user
Quote this message in a reply
10-01-2012, 10:05 AM
Post: #2
 
Its possible with a custom made PHP function. Please find the source to get more idea about this.


function ShowDate($date) // $date --> time(); value
{
$stf = 0;
$cur_time = time();
$diff = $cur_time - $date;
$phrase = array('second','minute','hour','day','week','month','year','decade');
$length = array(1,60,3600,86400,604800,2630880,31570560,315705600);
for($i =sizeof($length)-1; ($i >=0)&&(($no = $diff/$length[$i])<=1); $i--); if($i < 0) $i=0; $_time = $cur_time -($diff%$length[$i]);
$no = floor($no); if($no <> 1) $phrase[$i] .='s'; $value=sprintf("%d %s ",$no,$phrase[$i]);
if(($stf == 1)&&($i >= 1)&&(($cur_tm-$_time) > 0)) $value .= time_ago($_time);
return $value.' ago ,';
}


This function can display time or date as 1 days ago, 2 days ago, etc..

Ads

Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)