October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Display Relative Dates in WordPress

Learn how to show labels such as “5 minutes ago” in WordPress with PHP or block-editor JavaScript, and when to use a localized absolute date instead.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To display a label such as “5 minutes ago” in WordPress, use PHP’s human_time_diff() to calculate the duration, then wrap it in a translated phrase. For localized calendar dates, use wp_date() with a Unix timestamp. In block-editor JavaScript, the @wordpress/date package provides corresponding date helpers.

Display a relative date in a PHP theme or plugin

human_time_diff() returns a duration such as “5 minutes,” not the complete phrase “5 minutes ago.” Supply that phrase yourself and make it translatable. For a post timestamp, the general pattern is:

$timestamp = get_post_time( 'U', true, $post );
echo esc_html(
    sprintf(
        esc_html__( '%s ago', 'your-text-domain' ),
        human_time_diff( $timestamp )
    )
);

Replace your-text-domain with your theme or plugin’s text domain. This example requests the post time in GMT using the U format, which represents a Unix timestamp. Check the timestamp helper and timezone assumptions for your particular code path; human_time_diff() expects Unix timestamps for both its $from and $to arguments. If you omit $to, it uses the current server time, time(). See the WordPress function reference.

The example escapes the rendered string for HTML output and uses a translation function for the wrapper phrase. WordPress’s helper also supplies translated duration units, including their singular and plural forms. Avoid hard-coding a word such as “minutes” around the result: the returned unit varies with elapsed time.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What the relative-time result means

human_time_diff() calculates the absolute difference between its two timestamps and rounds it into a unit bucket. The buckets progress from seconds to minutes, hours, days, weeks, months, and years. The output is therefore a concise approximation, not an exact elapsed-time measurement.

Because the helper uses an absolute difference, its duration alone does not say whether the timestamp is in the past or future. The “%s ago” wrapper is appropriate when the date is known to be in the past. If your interface can receive future dates, determine the direction separately and choose wording that reflects it rather than labeling every result “ago.” The function reference documents the arguments and output behavior.

Rank #2
Sale
bloom daily planners Undated Perpetual Desk Easel/Inspirational Standing Flip Calendar - (5.25" x 5.5") (The Best is Yet to Come)
  • UNDATED desk easel by bloom daily planners - inspiring office supplies for women!
  • INSPIRATIONAL: 365+ daily empowering inspirational positive affirmations to motivate you each day (easel covers Leap Day) Start with this daily inspirational calendar any time of year, adding inspirational office decor and providing positive quotes of the day to stay motivated.
  • No years printed on pages - calendar easel is reusable year after year! Calendar is perpetual. This inspirational flip calendar is undated, giving you a page a day calendar starting today and beyond. Start anytime calendar.
  • Foil accents on cover. Full color designs change monthly, coordinated with the seasons! Home Office Decor for Women.
  • Great gifts for women and the perfect desk accessory. Daily inspirational quotes calendar with a page a day. Daily affirmations for women. We stand by our products and offer a no questions asked refund if you experience any issues with your product. Simply contact bloom directly through the Amazon messaging system. We will be happy to assist you and answer any questions. 100% customer satisfaction is what we strive for at bloom.

Show an absolute date in the WordPress site timezone

Relative labels are compact, but they do not tell readers the calendar date or time. For a localized absolute date, use wp_date() with a true Unix timestamp:

echo esc_html( wp_date( get_option( 'date_format' ), $timestamp ) );

wp_date() localizes the date and defaults to the WordPress site timezone. You can use a format based on the site’s date settings, as above, or provide another PHP date format appropriate to the display. See the WordPress wp_date() reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Do not treat date_i18n() as though its timestamp parameter has the same semantics as wp_date(). Its legacy behavior expects a value that includes a timezone offset added to the Unix timestamp. WordPress describes wp_date() as the newer replacement without those legacy quirks. See the WordPress date_i18n() reference.

Choose between relative and absolute display

A useful interface can show relative time for recent entries and switch to a localized date and time for older ones. This gives readers quick context for fresh activity while retaining calendar context when “weeks ago” or “months ago” is less informative. WordPress core uses this kind of split in its privacy-request table: for a non-empty timestamp less than one day old, it displays a translated “%s ago” label; otherwise it displays a localized date and time. That is an example of core behavior, not a rule every theme or plugin must follow. The example is in the WP_Privacy_Requests_Table reference.

Where precision matters, expose a comprehensible text label and include the absolute date or time as well. This is a usability recommendation; the cited API references do not prescribe a particular HTML element or accessibility standard for relative dates.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use WordPress date helpers in block-editor JavaScript

For editor-side interfaces, the @wordpress/date package offers JavaScript date functions. Its handbook documents dateI18n for localized formatting, similar to PHP’s wp_date(), and humanTimeDiff() for human-readable time differences. The documentation describes date inputs in the WordPress timezone. See the WordPress @wordpress/date package handbook.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Seize the Day 2027 Daily Desk Calendar: Boxed Page-a-Day Inspirational Calendar by Robin Pickens with Day-to-Day Uplifting Quotes & Colorful Art
  • 2027 Daily Desk Calendar: Page-a-day 2027 desk calendar featuring uplifting quotes and colorful artwork by Robin Pickens. Let the spirit of Robin Pickens and her vivacious combination of art and encouraging words inspire you throughout the year in a desktop tear-off format designed for daily display.
  • 320 Full-Color Pages: Includes 320 tear-off pages spanning January through December 2027. Saturday and Sunday are printed together on a single page. Each page features a trivia question, fact, or historical note in an easy-to-read layout.
  • Compact Desktop Format: Measures 5.9" x 5". Comes with a biodegradable paperboard easel for freestanding display on desks, counters, shelves, and workspaces.
  • Horror Genre Content: Covers classic and contemporary horror films, authors, characters, and behind-the-scenes information. Designed for general audiences interested in horror media.
  • Holiday & Moon Phase Reference: Includes major U.S., Canadian, United Kingdom, Australian, and New Zealand holidays, along with moon phases throughout the 2027 calendar year.

Do not assume a JavaScript date value can be passed around like a PHP Unix timestamp. The JavaScript helpers accept different input forms, including Moment objects, Date objects, strings, and numbers; verify the data shape where your code gets the value. For a server-rendered theme or plugin, PHP’s human_time_diff() is the direct option; for block-editor UI, use the package’s documented helpers.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.