Display Relative Dates in WordPress

Instead of displaying the exact date your post was published, you can display it relatively – “6 months ago” or “3 weeks ago”. Use the following code to do this:

# For posts & pages #
<?php echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ago'; ?>

# For comments #
<?php echo human_time_diff(get_comment_time('U'), current_time('timestamp')) . ' ago'; ?>

For another useful date/time display, see Display Estimated Post Reading Time.

Discussion
[  0 Comments  ]

Leave a Comment

To add code, use the buttons below. For instance, click the PHP button to insert PHP code within the shortcode. If you notice any typos, please let us know!