Tag

a 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.

Today, We are going to learn update or create the post publish time. We see the post publish date on many blogs the post publish 3 hours ago. So, How we can change the date format something like Converting Timestamp into a time ago on our WordPress blog. I am going to share step by step guide for date change like.

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

Yes, We can display the date like this on WordPress blog. So, let’s see how we can change the date format like this.

Converting Timestamp into a time ago in WordPress

We can implement this code by plugin or theme. So, let’s see If you want to implement this code by theme then open the functions.php file. If you want to implement this code by plugin hen open the mail file of your plugin. Then after, following the below function for converting the timestamp into a time ago string.

Now, let’s we are going to call the hook for change the publish date of Blog in WordPress.

We have created the hook get_the_date, the_date, the_time, get_the_time for change the WordPress Blog time. Just follow the above code then check the blog time is changed on your site.

If you face any issue or date is not changed like shown in an example please write the comment below.