# "Years Since" Shortcode

> Adds a [years_since] shortcode that prints how many full years have passed since a date, such as years in business, years of experience or a person's age, so the number never goes out of date.

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

## Code

```php
add_action( 'init', function () {
    add_shortcode( 'years_since', function ( $atts ) {
        $atts = shortcode_atts( array( 'date' => '' ), $atts, 'years_since' );

        $start = DateTimeImmutable::createFromFormat( '!Y-m-d', $atts['date'], wp_timezone() );
        if ( ! $start ) {
            return '';
        }

        return esc_html( number_format_i18n( $start->diff( new DateTimeImmutable( 'now', wp_timezone() ) )->y ) );
    } );
} );
```

## Notes

Example "Serving customers for [years_since date='2009-05-01'] years".

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find ""Years Since" Shortcode" 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/
