Codes for date and time

The following codes are used to pass formatted date and time strings to external programs. They are also quite often used to pass date strings to the internal commands - for example, to create a folder named after the current date, you might use a command like CreateFolder {date|yyyyMMdd}.

 

Code

Description

{date|<format>}

Current date (local time).

{dateu|<format>}

Current date (UTC).

{time|<format>}

Current time (local time).

{timeu|<format>}

Current time (UTC).

 

The <format> value is a string consisting of various tokens that are used to format the date and time strings. If no format is specified, your default system date and time format is used.


As an example, {date|yyyy-MM-dd} would format the date like 2016-09-22, and {time|HHmmss} would format the time like 084450.

 

While this page is primarily about the {date}, {dateu}, {time} and {timeu} codes, the syntax described below is also used in other places where date and time formats are used. The syntax is based on the one Windows uses, with some additions, and should be familiar if you have ever customized your Windows date-time format.

 

D# and T# prefixes: Date formats may begin with D#. Time formats may begin with T#. While these prefixes are optional for {date}, {dateu}, {time} and {timeu}, where the format type is implicit, the prefixes are required in situations where a code returns both a date and a time together. For example, when renaming files the {modified} code, a file's modified year could be inserted with {modified|D#yyyy}.

 

Special flags: A handful of special flags can appear at the start of the format string, after any D# or T# prefix, to modify how the formatting is performed. Like the main format flags, these are case sensitive. If two or more special flag are used at once, their order is not important.

The date codes use the following tokens - note that these tokens are case sensitive! The ISO week and ISO year tokens refer to the ISO week date system.

 

Date token

Description

d

Day of month as a number, with no leading zero for single-digit days.

dd

Day of month as a number, with a leading zero for single-digit days.

D

Day of week as a number (1 = Sunday, 7 = Saturday).

DD

Day of week as a number (1 = Monday, 7 = Sunday).

ddd

Day of week as a three-letter abbreviation (e.g. Wed).

dddd

Day of week as its full name (e.g. Wednesday).

w

ISO week number, no leading zero.

ww

ISO week number, leading zero.

W

Simple week number, no leading zero.

WW

Simple week number, leading zero.

M

Month as a number, no leading zero.

MM

Month as a number, leading zero.

MMM

Month as a three-letter abbreviation (e.g. Jan).

MMMM

Month as its full name (e.g. January).

y

Year as last two digits, but with no leading zero for years less than 10 (e.g. 2009 -> 9).

yy

Year as last two digits, with a leading zero (e.g. 2009 -> 09).

yyyy

Year as a four digit number.

Y

ISO year as last two digits, no leading zero. (Generally only makes sense in conjunction with ISO week. Do not use if you just want the normal year.)

YY

ISO year as last two digits, leading zero. (Generally only makes sense in conjunction with ISO week. Do not use if you just want the normal year.)

YYYY

ISO year as four digit number. (Generally only makes sense in conjunction with ISO week. Do not use if you just want the normal year.)

gg

Period/era string - ignored if the date to be formatted does not have an associated era.

 

The time codes use the following tokens - these are also case sensitive.

 

Time token

Description

h

Hours with no leading zero for single-digit hours, 12 hour clock.

hh

Hours with leading zero for single-digit hours, 12 hour clock.

H

Hours with no leading zero, 24 hour clock.

HH

Hours with leading zero, 24 hour clock.

m

Minutes with no leading zero.

mm

Minutes with leading zero.

s

Seconds with no leading zero. (Includes milliseconds, if the special M flag is specified. See above.)

ss

Seconds with leading zero. (Includes milliseconds, if the special M flag is specified. See above.)

t

One-character AM/PM string (e.g. A or P). See note about locales, above.

tt

Multiple-character AM/PM string. See note about locales, above.