Current PHP Date Time
Photo Credit

Current PHP Date & Time

Version: 3.2

A lightweight plugin that provides shortcodes for the current, Year, Month, Day, Time and more.

How to Use

Download > Install > Activate.

Insert shortcode [lwdatetime display="parameter(s)"], replacing parameter(s) with the desired output from the PHP date & time parameters below. Non-parameter characters will be rendered as it.

Date Parameters
d - Day of the month, 2 digits with leading zeros, example 01 to 31
D - A text representation of a day, three letters, example Mon through Sun
j - Day of the month without leading zeros, example 1 to 31
l - (lowercase ‘L’) A full text representation of the day of the week, example Sunday through Saturday
S - English suffix for the day of the month, 2 characters, example st, nd, rd or th.
w - Numeric representation of the day of the week, example 0 (for Sunday) through 6 (for Saturday)
z - The day of the year (starting from 0), example 0 through 365

Week Parameters
W - Week number of year, weeks starting on Monday, example 42 (the 42nd week in the year)

Year Parameters
L - Whether it’s a leap year, example 1 if it is a leap year, 0 otherwise.
Y - A four digit representation of a year, example 2004
y - A two digit representation of a year, example 04

Time Parameters
a - Lowercase Ante meridiem and Post meridiem, example am or pm
A - Uppercase Ante meridiem and Post meridiem, example AM or PM
g - 12-hour format of an hour without leading zeros, example 1 through 12
G - 24-hour format of an hour without leading zeros, example 0 through 23
h - 12-hour format of an hour with leading zeros, example 01 through 12
H - 24-hour format of an hour with leading zeros, example 00 through 23
i - Minutes with leading zeros, example 00 to 59
s - Seconds, with leading zeros, example 00 through 59

Timezone Parameters
e - Timezone identifier, example UTC, GMT, Atlantic/Azores
I - (capital i)Whether or not the date is in daylight saving time, example 1 if Daylight Saving Time, 0 otherwise.
O - Difference to Greenwich time (GMT) in hours, example +0200
P - Difference to Greenwich time (GMT) with colon, example +02:00
T - Timezone abbreviation, example EST, MDT

Full Date/Time Parameters
c - ISO 8601 formatted date, example 2004-02-12T15:19:21+00:00
r - RFC 2822 formatted date, examlpe Thu, 21 Dec 2000 16:01:07 +0200
U - Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT), example

Example

Copyright © Year
Insert shortcode [lwdatetime display="© Y"] to get © 2022

Multiple Formats in One Shortcode
Inserting shortcode [lwdatetime display="F jS"] would output F (full text of the month), then a space, then j (day of the month - no zero), then S (day of the month suffix). Example --> Today is October 1st

Multiple Formats in One Shortcode with Text
Inserting shortcode [lwdatetime display="h:i:s A"] would output hour:minute:second space capital AM/PM. The colons output as the character they are since they are not a parameter. Example --> The time is 11:54:29 AM

Avoid Conflicting Text
Inserting shortcode [lwdatetime display="Today is the z day of o."] would output gibberish since some of the letters are also recognized parameters. To achieve this you would use two shortcodes. Example --> Today is the [lwdatetime display="z"] day of [lwdatetime display="o"]. would output Today is the 273 day of 2022.

Source

This code can be pasted into the functions.php file of your child theme or, download and install the plugin for simple code activation.
/*
Plugin Name: Lightweight Plugins - Current PHP Date Time 
Plugin URI: https://lightweightplugins.com/plugin/current-php-date-time/
Description: A lightweight plugin that provides shortcodes for the current, Year, Month, Day, Time and more.
Version: 3.2
Author: WP Maintenance Experts
Author URI: https://wpmaintenanceexperts.com/
License: GPLv2 or later
*/

function build_lighweight_plugins_cpdt_shortcode( $atts ){
        $args = shortcode_atts(array(
    'display' => 'Y',
    ), $atts);
        $d = $args["display"];
  return date($d);
}
add_shortcode( 'lwdatetime', 'build_lighweight_plugins_cpdt_shortcode');

0 Comments

Submit a Comment

Your email address will not be published.