Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Facebook like time ago system in php

In this tutorial, we are going to learn how to make Facebook like time ago system in PHP. In my previous post we have learnt How to close a DIV container when clicking outside using Jquery, I know it’s kinda off topic, because in this topic we are going to learn to convert timestamp to time ago in PHP, but it is my duty to expose all those interesting articles so that you can learn more.

Guys If you have used Facebook and you update status on your wall, upload photo or share something on Facebook then after uploading it, It display time as Just Now or you can also see your previous post time, it show like one week or month or year or day ago.

facebook like time ago system in php

Importance of this System (Facebook like time ago system in PHP)

It is common to show dates on the Web in the format such as Published on January 12th, 2017, or 05/17/2017, 09:40:25 and 2017-09-12.

Each of the above examples shows the full date or time of some kind of activity on web applications – be it a published blog article, or a visitor comment, or perhaps an uploaded video.

Showing Date formats like above might seem perfectly reasonable. After all, they are informative and human readable! but “human readable” not at all necessary mean readers will readily be able to understand how recently the activity has occurred or added. The Internet is a fast-moving place, and giving your content a sense of freshness could be the key to engaging with your audience.

Let’s suppose you have stumbled on an article that was published just a couple of hours ago, but the subheading of the article states like:

Published on January 12th, 2017







The only problem with above messages is that they do not communicate the feeling that your activity has just been updated. So, surely it is more inviting and much clearer to display the time in this way:

Published 2 hours ago

Strategy And Logics

This function counts the time between the current date and time & previous date and time with simple PHP logic. This function converts the previous date into UNIX timestamp and also the current date in UNIX time. From the difference of this current UNIX timestamp and previous UNIX timestamp, we can get the number of seconds between these dates. From seconds we can easily get minutes, hours, days, weeks, months and years.

Time ago in PHP function

function time_ago_in_php($timestamp){
  $time_ago        = strtotime($timestamp);
  $current_time    = time();
  $time_difference = $current_time - $time_ago;
  $seconds         = $time_difference;
  $minutes = round($seconds / 60); // value 60 is seconds  
  $hours   = round($seconds / 3600); //value 3600 is 60 minutes * 60 sec  
  $days    = round($seconds / 86400); //86400 = 24 * 60 * 60;  
  $weeks   = round($seconds / 604800); // 7*24*60*60;  
  $months  = round($seconds / 2629440); //((365+365+365+365+366)/5/12)*24*60*60  
  $years   = round($seconds / 31553280); //(365+365+365+365+366)/5 * 24 * 60 * 60
  if ($seconds 

You just have to call the function like this:

echo time_ago_in_php(‘2017-06-16 10:57:03’);

So! this is all in facebook like time ago system in PHP module, to learn more programming tricks please share this with your friends, and don’t forget to subscribe our blog because as I said before we are going to post lots of interesting programming tutorials in future, stay tuned.

You may also like

  • Multi Level Nested Category System in Codeigniter and MySql
  • Get Users Latitude and Longitude using Google Place API and PHP
  • Resize Image Without Stretching in Codeigniter

The post Facebook like time ago system in php appeared first on My Programming Tutorials.

This post first appeared on My Programming Tutorials, please read the originial post: here

Share the post

Facebook like time ago system in php


Subscribe to My Programming Tutorials

Get updates delivered right to your inbox!

Thank you for your subscription