Time Ago Script

In this tutorials I explains time ago script like facebook.

<pre class="lang:default decode:true "]]><?php</p>
<p>$provided_time ='1445324970';</p>
<p>function php_time_ago($provided_time){ $time_difference = time() - $provided_time ;</p>
<p>$seconds = $time_difference ; $minutes = round($time_difference / 60 ); $hours = round($time_difference / 3600 );</p>
<p>$days = round($time_difference / 86400 ); $weeks = round($time_difference / 604800 ); $months = round($time_difference / 2419200 );</p>
<p>$years = round($time_difference / 29030400 ); if($seconds <= 60){ echo "$seconds seconds ago";
<p>}else if($minutes <=60) {
<p>{ echo "one minute ago";</p>
<p>echo "$minutes minutes ago";</p>
<p>} }else if($hours <=24){</p>
<p>echo "one hour ago";</p>
<p>echo "$hours hours ago";</p>
<p>} }else if($days <= 7){</p>
<p>{ echo "one day ago";</p>
<p>echo "$days days ago";</p>
<p>} }else if($weeks <= 4)</p>
<p>{ if($weeks==1</p>
<p>){ echo "one week ago";</p>
<p>} else{</p>
<p>echo "$weeks weeks ago";</p>
<p>} }else if($months <=12){</p>
<p>echo "one month ago";</p>
<p>echo "$months months ago";</p>
<p>} }else{ if($years==1){</p>
<p>echo "one year ago";</p>
<p>}else{ echo "$years years ago"; } } }</p>
<p>echo php_time_ago($provided_time);</p>
<p>?> </p>

Recommended Tutorials for you


Anuj kumar

This is Anuj Kumar. I’m a professional web developer with 5+ years of experience. I write blogs in my free time. I love to learn new technologies and share with others. I founded PHPGurukul in September 2015. The main aim of this website to provide PHP, Jquery, MySQL, PHP Oops and other web development tutorials. .


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Check Also
Back to top button