Skip to content
  • Products
  • Learn
  • About
  • Blog
  • Reviews
  • Contact
  • Log in
0

Display Human Readable Time

Posted On May 26, 2011

Categories Beginner
Tutorials

Tags post date, time

Comments Comments Off on Display Human Readable Time

Human readable time formats means that the date of a post or comment is displayed as “x time ago”. This format is much easier to read and interpret, and gives the reader a “relative sense” of when the item was published.

I have been using the human readable time format in my recent widget tutorials, so I thought I’d put out this quick tip on how you can do it as well.

We are going to use three different functions to achieve the desired effect:

  • human_time_diff() – determines difference between two times and returns in human readable format
  • get_the_time() – returns the publication time of the current post
  • current_time() – returns the current time of the server

The final code that will display our human readable time is:

echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ago';

echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ago';

This will display something like: “2 days ago”.

Posted On May 26, 2011

Categories Beginner
Tutorials

Tags post date, time

Comments Comments Off on Display Human Readable Time

Site Links

  • Home
  • Products
  • Learn
  • Blog
  • Refund Policy
  • Pippin Williamson
  • Reviews
  • Contact
  • Affiliate Area

Other Useful Links

  • Tag Index
  • Apply Filters
  • Support the Site
  • Plugin Support
  • Random Post
  • WPBeginner
  • WP Migrate DB Pro
  • Pippin.com
  • Sandhills Development, LLC

Recommended Products

  • AffiliateWP
  • Easy Digital Downloads
  • Restrict Content Pro
  • Sugar Calendar
  • SellBird
  • WP Simple Pay

Email Newsletter

Copyright © 2023 Sandhills Development, LLC