WP Date and Time Shortcode

Description

Use this plugin if you want to display a current, past or future date or time that may or may not change during every new visit of the specific page or post.

It takes lots of efforts to develop and support a plugin for free. Please send us your feedback and questions to fix your issue before leaving a bad review.

WARNING: If you are using a caching plugin you may need to exclude the page or post from it so the content may be generated dynamically with every single visit.

The shortcode tag can be used as both [wp-dt] and [wp_dt] at your choice. The attributes for the shortcode are:

  • ‘item’ – what date and time information to show. The used values are:
    • ‘datetime’ – default WP date and time format (default value)
    • ‘date’ – default WP date format
    • ‘time’ – default WP date format
    • ‘custom’ – custom format used by the built-in PHP date() function
    • ‘year’, ‘years’ – 4-digit year
    • ‘year-short’ – 2-digit year
    • ‘month’, ‘months’ – month as number (1-12)
    • ‘month-name’ – month as name (January-December)
    • ‘month-name-short’ – month as 3-letter name (Jan-Dec),
    • ‘day’, ‘days’ – day of month
    • ‘hour’, ‘hours’ – hours
    • ‘minute’, ‘minutes’ – minutes
    • ‘second’, ‘seconds’ – seconds
    • ‘day-of-year’ – day of the year as number
    • ‘days-in-month’ – number of days in the month
    • ‘days-in-february’ – number of days in the month of February for the year
    • ‘weekday’ – day of the week as number (1-7)
    • ‘weekday-name’ – day of the week as full name (Monday-Sunday)
    • ‘weekday-name-short’ – day of the week as full name (Mon-Sun)
    • ‘am-pm’ – shows am/pm or AM/PM according to the am_pm attribute (‘L’ or ‘U’)
    • ‘timezone’ – show the timezone
    • ‘timezone-abbreviation’ – show the timezone abbreviation
  • ‘format’ – format that can be used the PHP date() function, used only when ‘item’ is set to ‘custom’
  • ‘init’ – initial date and time string in mysql format
  • ‘i18n’ – set months and weeks names to be displayed in the current language
  • ‘months_zero’ – set leading zero for months
  • ‘days_zero’ – set leading zero for days
  • ‘days_suffix’ – set suffix st, nd, rd, th for days
  • ‘hours_zero’ – set leading zero for hours
  • ‘hours_24’ – set 24 or 12 hours format
  • ‘minutes_zero’ – set leading zeros for minutes
  • ‘seconds_zero’ – set leading zeros for seconds
  • ‘am_pm’ – used when 12 hours format is preferred: ‘L’ for lowercase (am, pm) or ‘U’ for uppercase (AM, PM)
  • ‘years’, ‘years_change’ – change in years
  • ‘months’, ‘months_change’ – change in months
  • ‘days’, ‘days_change’ – change in days
  • ‘hours’, ‘hours_change’ – change in hours
  • ‘minutes’, ‘minutes_change’ – change in minutes
  • ‘seconds’, ‘seconds_change’ – change in seconds

You can also use directly the following shortcodes with wp-dt-item and miss the ‘item’ attribute:

  • [wp-dt-datetime]
  • [wp-dt-date]
  • [wp-dt-time]
  • [wp-dt-custom]
  • [wp-dt-year], [wp-dt-years]
  • [wp-dt-year-short]
  • [wp-dt-month], [wp-dt-months]
  • [wp-dt-month-name]
  • [wp-dt-month-name-short]
  • [wp-dt-day], [wp-dt-days]
  • [wp-dt-hour], [wp-dt-hours]
  • [wp-dt-minute], [wp-dt-minutes]
  • [wp-dt-second], [wp-dt-seconds]
  • [wp-dt-day-of-year]
  • [wp-dt-days-in-month]
  • [wp-dt-days-in-february]
  • [wp-dt-weekday]
  • [wp-dt-weekday-name]
  • [wp-dt-weekday-name-short]
  • [wp-dt-am-pm]
  • [wp-dt-timezone]
  • [wp-dt-timezone-abbreviation]

Here are some samples of the shortcode with a variety of attributes and the results:

Show current date and time in default WordPress format:
[wp-dt] => 16/09/2019 17:45

Show current date only in the default WordPress format:
[wp-dt item=”date”] => 16/09/2019
or [wp-dt-date] => 16/09/2019

Show current time only in the default WordPress format:
[wp-dt item=”time”] => 17:45
or [wp-dt-time] => 17:45

Show current date and time with custom format:
[wp-dt item=”custom” format=”d F Y, H:i A”] => 16 September 2019, 17:45 PM
or [wp-dt-custom format=”d F Y, H:i A”] => 16 September 2019, 17:45 PM

Show the time 3 years, 4 months, 5 days, 6 hours, 20 minutes and 30 seconds ago starting from a specific date:
[wp-dt item=”custom” format=”M j, Y H:i:s a” init=”2019-09-16 17:45:53″ years=”-3″ months=”-4″ days=”-5″ hours=”-6″ minutes=”-20″ seconds=”-30″] => May 11, 2016 11:25:23 am
or [wp-dt-custom format=”M j, Y H:i:s a” init=”2019-09-16 17:45:53″ years=”-3″ months=”-4″ days=”-5″ hours=”-6″ minutes=”-20″ seconds=”-30″] => May 11, 2016 11:25:23 am

Show 4 and 2-digit year, month and day of month:
[wp-dt item=”year”], [wp-dt item=”year-short” years=”+2″], [wp-dt item=”month” months=”+1″], [wp-dt item=”day” days=”-1″ days_zero=”no”], [wp-dt item=”day” days_zero=”no” days_suffix=”yes”] => 2019, 21, 10, 15, 16th
or [wp-dt-year], [wp-dt-year-short years=”+2″], [wp-dt-month months=”+1″], [wp-dt-day days=”-1″ days_zero=”no”], [wp-dt-day days_zero=”no” days_suffix=”yes”] => 2019, 21, 10, 15, 16th

Show month name (previous, this and next month):
[wp-dt item=”month-name” months=”-1″], [wp-dt item=”month-name”], [wp-dt item=”month-name” months=”+1″] => August, September, October

Show month short three letter name (previous, this and next month):
[wp-dt item=”month-name-short” months=”-1″], [wp-dt item=”month-name-short”], [wp-dt item=”month-name-short” months=”+1″] => Aug, Sep, Oct
or [wp-dt-month-name-short months=”-1″], [wp-dt-month-name-short], [wp-dt-month-name-short months=”+1″] => Aug, Sep, Oct

Show week of the year, day of the year, days in the month, days in February for the year:
[wp-dt item=”week-of-year”], [wp-dt item=”day-of-year”], [wp-dt item=”days-in-month”], [wp-dt item=”days-in-february”] => 38, 259, 30, 28
or [wp-dt-week-of-year], [wp-dt-day-of-year], [wp-dt-days-in-month], [wp-dt-days-in-february] => 38, 259, 30, 28

Show weekday as number, full name or three letter name:
[wp-dt item=”weekday”], [wp-dt item=”weekday-name”], [wp-dt item=”weekday-name-short”] => 1, Monday, Mon
or [wp-dt-weekday], [wp-dt-weekday-name], [wp-dt-weekday-name-short] => 1, Monday, Mon

Show hours, minutes, seconds and am/pm:
[wp-dt item=”hours” hours_24=”no” hours_zero=”no”]:[wp-dt item=”minutes”]:[wp-dt item=”seconds”] [wp-dt item=”am-pm”] => 5:45:53 pm
or [wp-dt-custom format=”g:i:s a”] => 5:45:53 pm

Show a timezone and timezone abbreviation:
[wp-dt item=”timezone”], [wp-dt item=”timezone-abbreviation”] => Europe/Sofia, Т
or [wp-dt-timezone], [wp-dt-timezone-abbreviation] => Europe/Sofia, Т

Learn more at the page of WP Date and Time Shortcode or contact us by e-mail for more information.

Features

  • Show date and time in the default WordPress or customer format.
  • Show separately date and time
  • Show separately 4 or 2-digit year
  • Show month as number, full name (e.g January) or three letters (e.g. Jan)
  • Show day as number with or without leading zero, with or without suffix (st, nd, rd, th)
  • Show hour, minutes, seconds with or without leading zero
  • Show day of week as number, full name (e.g. Monday) or three letters (e.g. Mon)
  • Show the week of the year
  • Show the day of the year
  • Show the number of days for the month
  • Show the number of days in February for the year
  • Show timezone and timezone abbreviation
  • Show any combinations for date and time using the built-in PHP date() function format
  • Add or subtract years, months, days, hours, minutes and/or seconds before showing the final result.

Installation

From WordPress Dashboard

  1. Navigate to ‘Plugins -> Add New’ from your WordPress dashboard.
  2. Search for ‘WP Date and Time Shortcode’ and install it.
  3. Activate the plugin from the Plugins menu.

Manual Installation

  1. Download the plugin file: ‘wp-date-and-time-shortcode.zip’
  2. Unzip the file
  3. Upload the ‘wp-date-and-time-shortcode.zip’ folder to your ‘/wp-content/plugins’ directory (do not rename the folder).
  4. Activate the plugin from the Plugins menu.

It will start doing it’s job as soon as you put the shortcode in your page ot post. That’s all, folks!

FAQ

Can I use both [wp-dt] and [wp_dt] interchangeably?

Yes, you can. We have added both shortcode names because some people like underscores and others – hyphens, and it might lead to errors.

I have an idea how this plugin can be improved. Can I send it somehow?

Yes, please send all your suggestions and ideas to our e-mail address.

Contributors & Developers

“WP Date and Time Shortcode” is open source software. The following people have contributed to this plugin.

Contributors

Changelog

1.2

  • Added shorter version for the “_change” attributes removing the “_change” part.

1.1

  • More shortcodes added for easier and faster use by missing the “item” attribute.

1.0.1

  • A couple of bug fixes after the initial release

1.0

  • Initial release