jQuery & PHP Convert Date time to Facebook Style TimeAgo

Whenever a user sees a date or time, he/she start doing comparisons between current time and given time. So it takes some more brain resources to do time difference calculations. Facebook knows about this lazy human behavior, that’s why it always shows date time in the following format

less than a minute ago
17 minutes ago
1 Year ago

Instead of

30 May 2018 15:35:47
30 May 2018 15:18:33
23 May 2017 09:28:23

Method for jQuery

Here we will discuss a jQuery plugin to convert these traditional timestamps to facebook way.

See demo here

Step 1) Include jQuery and Time Ago plugin

Step 2) Add HTML having traditional Timestamps


Step 3) Now we will call time ago function


Complete HTML will look like as follow:


More sources



Method in PHP

We can use following PHP function convert DateTime stamp into time ago:

Called as

Output will be

Source: https://www.w3schools.in/php-script/time-ago-function/


Leave a Reply

Notify of