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 |
|||
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 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)