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.

Please see the description and the F.A.Q. section below, or contact us by e-mail if you need more information or support.

Features

  • Show date and time in the default WordPress or customer format.
  • Show separately date only or time only.
  • 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 day of the year.
  • Show the week 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.
  • Show any item based on the first day from a list of next coming weekdays, days of month, or the last day of the current month.
  • Add or subtract years, months, days, hours, minutes and/or seconds before showing the final result.
  • Set post/page creation or modification time (including GMT variants) as “init” attribute.

Shortcode/s and attributes

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:
    • date-time, datetime – default WP date and time format (default value)
    • date – default WP date format
    • time – default WP time 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 short 3-letter name (Mon-Sun)
    • week-of-year – week of year, since first Monday of the year (1-52)
    • 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 – date format used with the PHP date() function only when item is set to custom
  • init – set the basic date and time for the shortcode; defaults to the WordPress time in the current timezone.
    • initial date and time string (preferably in MySQL format – Y-m-d H:i:s e.g. “2019-09-16 17:45:53”)
    • post-created – gets the post/page creation date and time
    • post-created-gmt – gets the post/page creation date and time GMT
    • post-modified – gets the post/page last modification date and time
    • post-modified-gmt – gets the post/page last modification date and time GMT
  • next – move the init date and time to the next coming selected (can have more than one value separated by comma)
    • mon, tue, wed, thu, fri, sat, sun – weekday shortname
    • 131 – day of month
    • last-day-of-month – the last day of month – 28, 29, 30 or 31
  • i18n – set months and weeks names to be displayed in the current language (‘on’ by default)
  • 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

IMPORTANT: Please always use straight quotes when adding the attributes. The curly/smart ones are not recognized by the WordPress shortcode functions.

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

  • [wp-dt-date-time]
  • [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-days-in-year]
  • [wp-dt-weekday]
  • [wp-dt-weekday-name]
  • [wp-dt-weekday-name-short]
  • [wp-dt-week-of-year]
  • [wp-dt-am-pm]
  • [wp-dt-timezone]
  • [wp-dt-timezone-abbreviation]

Shortcode/s usage examples

Examples of the shortcode/s usage with a variety of attributes and the results

  • For the examples a random creation date and time are used (2019-09-16 17:45:53 i.e. Sep 16, 2019 17:45:53)
  • The examples are in the following display format: [shortcode sample] => visible result.

Show current date and time in default WordPress format:
[wp-dt] => 16/09/2019 17:45
or [wp-dt item="date-time"] => 16/09/2019 17:45
or [wp-dt-date-time] => 16/09/2019 17:45
(The default WordPress date and time format is used.)

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-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-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 post/page creation and modification date and time in European format:
[wp-dt-custom init=”post-created” format=”j.n.Y G:i”] => 25.6.2019 9:14
[wp-dt-custom init=”post-modified” format=”j.n.Y G:i”] => 14.8.2019 14:48

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

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

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

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

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

Show hours, minutes, seconds and am/pm:
[wp-dt-hours hours_24=”no” hours_zero=”no”]:[wp-dt-minutes]:[wp-dt-seconds] [wp-dt item=”am-pm”] => 5:45:53 pm
or much shorter if you can use the PHP date() function format characters
[wp-dt-custom format=”g:i:s a”]` => 5:45:53 pm

Show next day, weekday, or last day of month from a list (weekly or monthly repeating dates).
[wp-dt-custom format=”D, M j – H:i” next=”Fri 19:30″] => Sep 20 19:30
[wp-dt-date-time next=”Sat 10:00, Sun 11:00″] => 21/09/2019 10:00
[wp-dt-date-time next=”1, 14, 20, tue 18:00, thu 18:00, last-day-of-month”] => 17/09/2019 18:00
[wp-dt-custom format=”d M H a” next=”5 10:00, 10 11:00, 15 10:30, 20 10:30, 25 10:40, 30″] => 20 Sep, 10 am

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.

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 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 or 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. However in the wp-dt-item shortcode format (when the item attribute is missed) only hyphens can be used.

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.

I have copied from your sample code on this page and the attributes do not work. Why?

When sample code is shown on this plugin’s description page or support forum, due to some reason the straight quotes may be automatically converted to curly/smart ones by the page generator. Please always use straight quotes in your pages when adding the attributes. The curly ones are not recognized by the WordPress shortcode functions and do not work.

Reviews

November 21, 2019
For date calculation use " " and everything will work fine! thank you!
Read all 2 reviews

Contributors & Developers

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

Contributors

Changelog

2.2.1

  • Fix: Item days-in-month works even when PHP on server is complied without –enable-calendar option.
  • Set WordPress 5.3.2 compatibility.

2.2

  • Shortcode item days-in-year added.
  • Shortcode duplicate/alias item date-time for item datetime.
  • Added next attribute that helps in displaying the next date from a list of weekdays, days of month, or the last day of the current month.
  • Framework update and bug fixes.

2.1.1

  • Bug fix: week-of-year item not showing correctly.

2.1

  • Framework update and bug fixes.

2.0

  • Added Denra Plugins Framework 1.0.
  • Added feature to set the init attribute from page/post creation or modification time.

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