Articles in this section

Date and time format codes

integrator.io uses the moment.js JavaScript library to format dates and times in Handlebars templates. Pass a moment.js format token to the dateFormat helper to control how a timestamp is rendered — for example, the month as a number, the full day name, or a localized date string. Use triple braces ({{{ }}}) so that integrator.io doesn't escape the formatted output.

All results in this article are based on the timestamp 2020-07-09T19:59:39.161Z.

Usage

{{{dateFormat "token" timeStamp}}}

token -- One or more format codes from the tables below. You can combine multiple tokens and literal text in a single expression, for example YYYY-MM-DD. Required.

timeStamp -- The date field or value to format. Required.

Month and quarter

Token Description Expression Result
M Month, 1 through 12, no leading zero {{{dateFormat "M" timeStamp}}} 7
Mo Month with ordinal, 1st through 12th {{{dateFormat "Mo" timeStamp}}} 7th
MM Month, 01 through 12, two digits {{{dateFormat "MM" timeStamp}}} 07
MMM Month, three-letter abbreviation {{{dateFormat "MMM" timeStamp}}} Jul
MMMM Full month name {{{dateFormat "MMMM" timeStamp}}} July
Q Quarter, 1 through 4 {{{dateFormat "Q" timeStamp}}} 3
Qo Quarter with ordinal, 1st through 4th {{{dateFormat "Qo" timeStamp}}} 3rd

Day

Token Description Expression Result
D Day of month, 1 through 31, no leading zero {{{dateFormat "D" timeStamp}}} 9
Do Day of month with ordinal {{{dateFormat "Do" timeStamp}}} 9th
DD Day of month, 01 through 31, two digits {{{dateFormat "DD" timeStamp}}} 09
DDD Day of year, 1 through 365, no leading zero {{{dateFormat "DDD" timeStamp}}} 191
DDDo Day of year with ordinal {{{dateFormat "DDDo" timeStamp}}} 191st
DDDD Day of year, 001 through 365, three digits {{{dateFormat "DDDD" timeStamp}}} 191
d Day of week, 0 (Sunday) through 6 (Saturday) {{{dateFormat "d" timeStamp}}} 4
do Day of week with ordinal {{{dateFormat "do" timeStamp}}} 4th
dd Day of week, two-letter abbreviation {{{dateFormat "dd" timeStamp}}} Th
ddd Day of week, three-letter abbreviation {{{dateFormat "ddd" timeStamp}}} Thu
dddd Full day name {{{dateFormat "dddd" timeStamp}}} Thursday
e Locale day of week, 0 through 6; lets you set a first day of the week other than Sunday {{{dateFormat "e" timeStamp}}} 4
E ISO day of week, 1 (Monday) through 7 (Sunday) {{{dateFormat "E" timeStamp}}} 4

Week and year

Token Description Expression Result
W Week of year, 1 through 53, no leading zero {{{dateFormat "W" timeStamp}}} 28
Wo Week of year with ordinal {{{dateFormat "Wo" timeStamp}}} 28th
WW Week of year, 01 through 53, two digits {{{dateFormat "WW" timeStamp}}} 28
YY Year, two digits {{{dateFormat "YY" timeStamp}}} 20
YYYY Year, four digits {{{dateFormat "YYYY" timeStamp}}} 2020
Y Year, four digits; ISO 8601-compliant for years past 9999 {{{dateFormat "Y" timeStamp}}} 2020
gg Week year, two digits {{{dateFormat "gg" timeStamp}}} 20
gggg Week year, four digits {{{dateFormat "gggg" timeStamp}}} 2020
GG ISO week year, two digits {{{dateFormat "GG" timeStamp}}} 20
GGGG ISO week year, four digits {{{dateFormat "GGGG" timeStamp}}} 2020

AM/PM and hour

Token Description Expression Result
A AM or PM, uppercase {{{dateFormat "A" timeStamp}}} PM
a am or pm, lowercase {{{dateFormat "a" timeStamp}}} pm
H Hour, 24-hour clock (0 through 23), no leading zero {{{dateFormat "H" timeStamp}}} 19
HH Hour, 24-hour clock (00 through 23), two digits {{{dateFormat "HH" timeStamp}}} 19
h Hour, 12-hour clock (1 through 12), no leading zero {{{dateFormat "h" timeStamp}}} 7
hh Hour, 12-hour clock (01 through 12), two digits {{{dateFormat "hh" timeStamp}}} 07
k Hour, 1 through 24, no leading zero {{{dateFormat "k" timeStamp}}} 19
kk Hour, 01 through 24, two digits {{{dateFormat "kk" timeStamp}}} 19

Minute, second, and fractional second

Token Description Expression Result
m Minute, no leading zero {{{dateFormat "m" timeStamp}}} 59
mm Minute, two digits {{{dateFormat "mm" timeStamp}}} 59
s Second, no leading zero {{{dateFormat "s" timeStamp}}} 39
ss Second, two digits {{{dateFormat "ss" timeStamp}}} 39
S Fractional second, 1 digit {{{dateFormat "S" timeStamp}}} 1
SS Fractional second, 2 digits {{{dateFormat "SS" timeStamp}}} 16
SSS Fractional second, 3 digits {{{dateFormat "SSS" timeStamp}}} 161
SSSS through SSSSSSSSS Fractional second, 4 to 9 digits; extra positions are padded with trailing zeros {{{dateFormat "SSSS" timeStamp}}} through {{{dateFormat "SSSSSSSSS" timeStamp}}} 1610 through 161000000

Time zone offset and Unix timestamp

Token Description Expression Result
Z UTC offset, colon-separated {{{dateFormat "Z" timeStamp}}} +00:00
ZZ UTC offset, no colon {{{dateFormat "ZZ" timeStamp}}} +0000
X Unix timestamp, in seconds {{{dateFormat "X" timeStamp}}} 1594324779
x Unix timestamp, in milliseconds {{{dateFormat "x" timeStamp}}} 1594324779161

Localized formats

Token Description Expression Result
LT Time {{{dateFormat "LT" timeStamp}}} 7:59 PM
LTS Time with seconds {{{dateFormat "LTS" timeStamp}}} 7:59:39 PM
L Date, MM/DD/YYYY {{{dateFormat "L" timeStamp}}} 07/09/2020
l Date, M/D/YYYY {{{dateFormat "l" timeStamp}}} 7/9/2020
LL Month name, day, year {{{dateFormat "LL" timeStamp}}} July 9, 2020
ll Abbreviated month, day, year {{{dateFormat "ll" timeStamp}}} Jul 9, 2020
LLL Month name, day, year, and time {{{dateFormat "LLL" timeStamp}}} July 9, 2020 7:59 PM
lll Abbreviated date and time {{{dateFormat "lll" timeStamp}}} Jul 9, 2020 7:59 PM
LLLL Day name, full date, and time {{{dateFormat "LLLL" timeStamp}}} Thursday, July 9, 2020 7:59 PM
llll Abbreviated day, date, and time {{{dateFormat "llll" timeStamp}}} Thu, Jul 9, 2020 7:59 PM

Common format strings

Combine the codes above to match the format an application expects. These are the strings most often used in integrator.io, with the result for the same timestamp.

Format string Result Typical use
YYYY-MM-DDTHH:mm:ssZ 2020-07-09T19:59:39+00:00 ISO 8601 with a UTC offset; most REST APIs
YYYY-MM-DDTHH:mm:ss[Z] 2020-07-09T19:59:39Z ISO 8601 in UTC, with a literal Z
YYYY-MM-DDTHH:mm:ss.SSSZZ 2020-07-09T19:59:39.161+0000 ISO 8601 with milliseconds and an offset without a colon
YYYY-MM-DD HH:mm:ss 2020-07-09 19:59:39 Databases and CSV files
YYYY-MM-DD 2020-07-09 Date-only fields
MM/DD/YYYY hh:mm A 07/09/2020 07:59 PM US-style display dates
DD/MM/YYYY 09/07/2020 Day-first display dates
YYMMDD 200709 Compact dates in file names and EDI
X 1594324779 Unix timestamp in seconds

Literal text

Wrap text in square brackets to include it literally without interpreting it as format codes. For example, {{{dateFormat "YYYY-MM-DD [order date]" timeStamp}}} returns 2020-07-09 order date.

Notes and constraints

  • Use triple braces ({{{ }}}) so that the formatted output isn't HTML-escaped.
  • Combine multiple tokens and literal text in a single expression, for example YYYY-MM-DD HH:mm.
  • Additional S characters beyond three pad the fractional seconds with trailing zeros, up to nine digits (SSSSSSSSS).