PHPGurukul

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>if($minutes==1)</p>
<p>{ echo "one minute ago";</p>
<p>}else{</p>
<p>echo "$minutes minutes ago";</p>
<p>} }else if($hours <=24){</p>
<p>if($hours==1){</p>
<p>echo "one hour ago";</p>
<p>}else{</p>
<p>echo "$hours hours ago";</p>
<p>} }else if($days <= 7){</p>
<p>if($days==1)</p>
<p>{ echo "one day ago";</p>
<p>}else{</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>if($months==1){</p>
<p>echo "one month ago";</p>
<p>}else{</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>

Anuj Kumar

This is Anuj Kumar. I’m a professional web developer with 4+ year 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.
.

Recommended Tutorials for you


4 comments

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

Follow us

Don't be shy, get in touch. We love meeting interesting people and making new friends.