Tag

time ago

Browsing

Today, We are going to learn PHP Converting Timestamp into a time ago. PHP provides date functions for print the date. PHP date function returns the date something like.

print date(“Y-m-d H:s:i”);

output : 2019-02-26 6:39:45

PHP date function returns date like the above format. Also, You can customize the output of date function using date options. But you want to display the time like a time ago then you can achieve that PHP code that we are going to learn today.

  • a second ago
  • a minute ago
  • a days ago
  • a month ago
  • a year ago

PHP Converting Timestamp into a time ago

We can easily get the date like above. I have created a function for convert date to time ago string. Using that function you can easily convert date and time.

Use the above function into your code and then pass the date and time argument on the function then check the output. let’s see the example of how to use converElapsedTime function.

echo converElapsedTime(‘2017-06-23 19:23:15’);

output : a year ago

So, It’s too easy to convert a date and time to time ago string. If face any issue after using this function please write the comment below.