RSS

How To Show “Time Ago” Style Dates In WordPress

13 Sep

In most of the themes, date and time are shown along with post title. Dates are shown below post titles. Date and time are shown below post comments. The format of dates may be mm-dd-yyyy, Month Day, Year or any other formats which the web admin likes.

It is more useful sometimes to display date and time in “Time Ago” style. It looks like 14 hours ago, 2 days ago, 3 weeks ago, 3 years ago etc. WordPress supports this style using human_time_diff() function. You can convert dates to this format using the code given below.

1
2
3
4
5
//To print post entry’s time (“2 days ago”):
echo human_time_diff( get_the_time(‘U’), current_time(‘timestamp’) ) . ‘ ago’;
//To print comment’s time:
echo human_time_diff( get_comment_time(‘U’), current_time(‘timestamp’) ) . ‘ ago’;
Advertisements
 
1 Comment

Posted by on September 13, 2013 in Wordpress

 

One response to “How To Show “Time Ago” Style Dates In WordPress

  1. Pingback: My Homepage

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: