Home / Widgets / Show current day, month, year in various formats
Duplicate Snippet

Embed Snippet on Your Site

Show current day, month, year in various formats

Return the current date and parts of current date in various formats

Code Preview
// [d] – inserts the current day with two digits e.g. 06
// [D] – inserts the current day with three letters e.g. Mon
// [j] – inserts the current day without leading zeros e.g. 6
// [l] – inserts the current day as a text e.g. Monday   (lower case L)
// [N] - inserts the ISO-8601 numeric representation of a day (1 for Monday, 7 for Sunday)
// [S] - inserts the English ordinal suffix for the day of the month (2 characters st, nd, rd or th. Works well with j)
// [w] - inserts a numeric representation of the day (0 for Sunday, 6 for Saturday)
// [z] - inserts the day of the year (from 0 through 365)
// [W] - inserts the ISO-8601 week number of year (weeks starting on Monday)
// [F] – inserts the current month as a text e.g. January
// [m] – inserts the current month with two digits e.g. 01
// [M] – inserts the current month with three letters e.g. Jan
// [n] – inserts the current month without leading zeros e.g. 1
// [Y] – inserts the current year with four digits e.g. 2023
// [y] – inserts the current year with two digits e.g. 23
// [date-long] - e.g. August 15, 2027
// [date-dmy] - e.g. 31/3/2026
// [date-mdy] - e.g. 4/28/2026
function day_two_digits() {return date('d');}
function day_text_three_letters() {return date('D');}
function day_two_digits_no_zero() {return date('j');}
function day_text() {return date('l');}
function day_ISO() {return date('N');}
function day_ordinal() {return date('S');}
function day_of_week() {return date('w');}
function day_of_year() {return date('z');}
function week_of_year() {return date('W');}
function month_text() {return date('F');}
function month_two_digits() {return date('m');}
function month_text_three_letters() {return date('M');}
function month_two_digits_no_zero() {return date('n');}
function year_four_digits() {return date('Y');}
function year_two_digits() {return date('y');}
function date_long() {return date('F').date('j').",&nbsp;".date('Y');}
function date_dmy() {return date('d')."-".date('m')."-".date('Y');}
function date_mdy() {return date('m')."-".date('d')."-".date('Y');}
add_shortcode('d', 'day_two_digits');
add_shortcode('D', 'day_text_three_letters');
add_shortcode('j', 'day_two_digits_no_zero');
add_shortcode('l', 'day_text');
add_shortcode('N', 'day_ISO');
add_shortcode('S', 'day_ordinal');
add_shortcode('w', 'day_of_week');
add_shortcode('z', 'day_of_year');
add_shortcode('W', 'week_of_year');
add_shortcode('F', 'month_text');
add_shortcode('m', 'month_two_digits');
add_shortcode('M', 'month_text_three_letters');
add_shortcode('n', 'month_two_digits_no_zero');
add_shortcode('Y', 'year_four_digits');
add_shortcode('y', 'year_two_digits');
add_shortcode('date-long', 'date_long');
add_shortcode('date-dmy', 'date_dmy');
add_shortcode('date-mdy', 'date_mdy');


Add a Comment