# Formatted Date Shortcode With Offsets

> Adds a [show_date] shortcode that prints today's date, or a date relative to it such as "+3 days" or "next friday", in any format, for delivery promises, deadlines and offer end dates.

- Type: PHP
- Runs: Run everywhere
- Category: [Content](https://wpide.com/library/category/content/)
- Tags: shortcodes, dates, time
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/date-offset-shortcode/

## Code

```php
add_action( 'init', function () {
    add_shortcode( 'show_date', function ( $atts ) {
        $atts = shortcode_atts( array( 'format' => get_option( 'date_format' ), 'offset' => '' ), $atts, 'show_date' );

        $now = new DateTimeImmutable( 'now', wp_timezone() );
        if ( '' !== trim( $atts['offset'] ) ) {
            $offset = sanitize_text_field( $atts['offset'] );
            // Reject text PHP cannot parse instead of letting modify() warn.
            if ( false === strtotime( $offset ) ) {
                return '';
            }
            $now = $now->modify( $offset );
        }

        return '<time datetime="' . esc_attr( $now->format( 'Y-m-d' ) ) . '">' . esc_html( wp_date( $atts['format'], $now->getTimestamp() ) ) . '</time>';
    } );
} );
```

## Notes

Example [show_date offset="+2 weekdays" format="l, F j"]; uses the site time zone. Pages cached by a caching plugin show the date they were cached.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Formatted Date Shortcode With Offsets" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
