Date & Time Patterns

This page explains how to define a pattern to output a certain date, time or dateTime in a certain way. You specify the pattern according to the rules and elements specified below.

You can specify custom date & time patterns in the date & time functions, or in the custom date option as described on this page:

For custom date formatting, Y is used for year in the custom date pattern, instead of y. The lowercase y is a calendar year pattern, and the uppercase Y is a week year pattern.

Elements of a pattern

A pattern consists of time elements and, optionally, static elements. Time elements represent a time unit, such as a year, a month, a day, but also an AM/PM notation, a timezone etc.

For instance:

  • yyyy-MM-dd = 2015-07-15 for July 15th in 2015. Both - are static elements, all the rest are time elements.
  • dd/MM/yyyy = 15/07/2015 for July 15th in 2015. Both / are static elements, all the rest are time elements.
  • dd 'days' = 30 days for a period of 30 days. The word days is static, dd is the time element representing days.

Using both time and static elements allows you to make your own custom date & time patterns.

Time elements

You can use the following time elements in the pattern by just putting their symbol directly into the pattern.

We'll use the following datetime as the example: 2015, July 15th, 03:45:30. Locale: English (en). Time zone: Pacific Standard Time

symbol meaning example extra info
G era AD  
y year (4 digits) 2015 This is a year as most people and businesses use it.
yy year (2 digits) 15
Y week year (4 digits) 2015

A week year is a year where all the weeks in the year are whole weeks.

More information on https://en.wikipedia.org/wiki/ISO_week_date.

YY week year (2 digits) 15
M month (1 digit if possible) 7  
MM month (2 digits) 07  
MMM month (short notation) Jul Depends on the locale.
MMMM month (long notation) July
w week in year (1 digit if possible) 29 29 = the 29th week in the year
ww week in year (2 digits) 29
W week in month (1 digit if possible) 3 3 = the 3rd week in July 2015
WW week in month (2 digits) 03
D day in year (1 digit if possible) 196  
DD day in year (2 digits if possible) 196  
DDD day in year (3 digits) 196  
d day in month (1 digit if possible) 15  
dd day in month (2 digits) 15  
F day of week in month (number) 3 3 = the 3rd wednesday in July 2015
u day of week in week (number) 3 3 = the 3rd day of the week
E day of week (short notation) Wed Depends on the locale.
EEEE day of week (long notation) Wednesday
a AM/PM marker AM  
H hour in day (0-23) (1 digit if possible) 3  
HH hour in day (0-23) (2 digits) 03  
k hour in day (1-24) (1 digit if possible) 3  
kk hour in day (1-24) (2 digits) 03  
K hour in AM/PM (0-11) (1 digit if possible) 3  
KK hour in AM/PM (0-11) (2 digits) 03  
h hour in AM/PM (1-12) (1 digit if possible) 3  
hh hour in AM/PM (1-12) (2 digits) 03  
m minute in hour (1 digit if possible) 45  
mm minute in hour (2 digits) 45  
s second in minute (1 digit if possible) 30  
ss second in minute (2 digits) 30  
S millisecond (1 digit if possible) 0  
SS millisecond (2 digits if possible) 00  
SSS millisecond (3 digits) 000  
z time zone (general) (short notation) PST  
zzzz time zone (general) (long notation) Pacific Standard Time  
Z time zone (RFC 822) -0800  
X time zone (ISO 8601) (short) -08  
XX time zone (ISO 8601) (normal) -0800  
XXX time zone (ISO 8601) (long) -08:00  

Static elements

You can use both symbols and letters as static elements. You can use the following symbols by putting them directly in the pattern:

/ * - + & ! ( ) { } [ ] , . ; : < > _ - # @

If you want to use a ' (apostrophe), you need to put 2 of them, like so:

''

If you want to use letters, you need to put them in between apostrophes, like so:

'a'  'days'  'a whole sentence'

Putting that all together, if you want your pattern to say 7 o'clock (where 7 is the hour), here's the pattern you need to specify:

h 'o''clock'

Defining a pattern

In the mapping window

When you have a date in a field, or as the output of an expression, you can use the custom date option in the Format tab of the mapping window to specify a pattern:

Just start typing into the box next to Pattern or select the ... to select a pre-made pattern, that you can then adjust.

In an expression

Defining a pattern in an expression is necessary for quite a few functions, such as formatDate, formatTime, toDateF, toTimeF etc. For instance:

formatDate(currentDate(),'yyyy-MM-dd')formatTime(currentTime(),'hh:mm')

As always with expressions, you need to put strings (such as a date & time pattern) in between ' ' (apostrophes).

Note: This, however, makes it a bit harder to use letters in your patterns, as you can't simply use apostrophes, since those are used to delineate the beginning and ending of the pattern in an expression.

To remedy this, you can escape your apostrophes by putting a \ (backslash) in front of them. So, instead of...

dd 'days'h 'o''clock' 

...you type this:

dd \'days\'h \'o\'\'clock\' 

It may look a bit strange, but it will definitely get the job done. Here are examples of the above patterns. Notice the apostrophe before and after the entire pattern:

formatPeriod(10000000,'dd \'days\'')

formatDate(currentDate(),'h \'o\'\'clock\'') 

Examples

Let's end with a few examples. For all of the following, the given date and time are 2001-07-04 12:08:56 local time in the U.S. Pacific Time time zone.

In the mapping window

These patterns don't require apostrophes like expressions would.

pattern output

yyyy.MM.dd G 'at' HH:mm:ss z

2001.07.04 AD at 12:08:56 PDT

EEE, MMM d, ''yy

Wed, Jul 4, '01

h:mm a

12:08 PM

hh 'o''clock' a, zzzz

12 o'clock PM, Pacific Daylight Time

K:mm a, z

0:08 PM, PDT

yyyyy.MMMMM.dd GGG hh:mm aaa

02001.July.04 AD 12:08 PM

EEE, d MMM yyyy HH:mm:ss Z

Wed, 4 Jul 2001 12:08:56 -0700

yyMMddHHmmssZ

010704120856-0700

yyyy-MM-dd'T'HH:mm:ss.SSSZ

2001-07-04T12:08:56.235-0700

yyyy-MM-dd'T'HH:mm:ss.SSSXXX

2001-07-04T12:08:56.235-07:00

YYYY-'W'ww-u

2001-W27-3

In an expression

The following patterns include the apostrophes used in an expression to delineate the beginning and ending of a string.

pattern output

'yyyy.MM.dd G \'at\' HH:mm:ss z'

2001.07.04 AD at 12:08:56 PDT

'EEE, MMM d, \'\'yy'

Wed, Jul 4, '01

'h:mm a'

12:08 PM

'hh \'o\'\'clock\' a, zzzz'

12 o'clock PM, Pacific Daylight Time

'K:mm a, z'

0:08 PM, PDT

'yyyyy.MMMMM.dd GGG hh:mm aaa'

02001.July.04 AD 12:08 PM

'EEE, d MMM yyyy HH:mm:ss Z'

Wed, 4 Jul 2001 12:08:56 -0700

'yyMMddHHmmssZ'

010704120856-0700

'yyyy-MM-dd'T'HH:mm:ss.SSSZ'

2001-07-04T12:08:56.235-0700

'yyyy-MM-dd'T'HH:mm:ss.SSSXXX'

2001-07-04T12:08:56.235-07:00

'YYYY-\'W\'ww-u'

2001-W27-3