Date manipulation

To get the current date in UTC, use the marker {c.now} in your template. The current date in UTC is returned only if the complement object option.complement is not overwritten by custom data.

formatD( patternOut, patternIn )

  • formats dates

  • takes an output date pattern as an argument

  • change the timezone through the option options.timezone and the lang through options.lang

ParametersDescriptionType

patternOut

output format

string

patternIn

  • [optional] input format

  • ISO 8601 by default

string

Examples

// with options = {
//   "lang": "en",
//   "timezone": "Europe/Paris"
// }
'20160131':formatD('L') // "01/31/2016"
'20160131':formatD('LL') // "January 31, 2016"
'20160131':formatD('LLLL') // "Sunday, January 31, 2016 1:00 AM"
'20160131':formatD('dddd') // "Sunday"
// with options = {
//   "lang": "fr",
//   "timezone": "Europe/Paris"
// }
'2017-05-10T15:57:23.769561+03:00':formatD('LLLL') // "mercredi 10 mai 2017 14:57"
'2017-05-10 15:57:23.769561+03:00':formatD('LLLL') // "mercredi 10 mai 2017 14:57"
'20160131':formatD('LLLL') // "dimanche 31 janvier 2016 01:00"
'20160131':formatD('dddd') // "dimanche"
// with options = {
//   "lang": "fr",
//   "timezone": "Europe/Paris"
// }
'20160131':formatD('dddd', 'YYYYMMDD') // "dimanche"
1410715640:formatD('LLLL', 'X') // "dimanche 14 septembre 2014 19:27"
// with options = {
//   "lang": "fr",
//   "timezone": "Asia/Singapore"
// }
'20160131':formatD('dddd', 'YYYYMMDD') // "dimanche"
1410715640:formatD('LLLL', 'X') // "lundi 15 septembre 2014 01:27"

formatI( patternOut, patternIn )

Formats intervals/duration.

Format names

  • human+

  • human

  • millisecond(s) or ms

  • second(s) or s

  • minute(s) or m

  • hour(s) or h

  • year(s) or y

  • month(s) or M

  • week(s) or w

  • day(s) or d

ParametersDescriptionType

patternOut

output format: human, human+, milliseconds, seconds,...

string

patternIn

[optional] input unit: milliseconds, seconds,...

string

Examples

// with options = {
//   "lang": "en",
//   "timezone": "Europe/Paris"
// }
2000:formatI('second') // 2
2000:formatI('seconds') // 2
2000:formatI('s') // 2
3600000:formatI('minute') // 60
3600000:formatI('hour') // 1
2419200000:formatI('days') // 28
// with options = {
//   "lang": "fr",
//   "timezone": "Europe/Paris"
// }
2000:formatI('human') // "quelques secondes"
2000:formatI('human+') // "dans quelques secondes"
-2000:formatI('human+') // "il y a quelques secondes"
// with options = {
//   "lang": "en",
//   "timezone": "Europe/Paris"
// }
2000:formatI('human') // "a few seconds"
2000:formatI('human+') // "in a few seconds"
-2000:formatI('human+') // "a few seconds ago"
// with options = {
//   "lang": "en",
//   "timezone": "Europe/Paris"
// }
60:formatI('ms', 'minute') // 3600000
4:formatI('ms', 'weeks') // 2419200000
// with options = {
//   "lang": "en",
//   "timezone": "Europe/Paris"
// }
'P1M':formatI('ms') // 2592000000
'P1Y2M3DT4H5M6S':formatI('hour') // 10276.085

addD( amount, unit, patternIn )

  • adds a time to a date

  • available units: day, week, month, quarter, year, hour, minute, second and millisecond

    • units are case insensitive, and support plural and short forms

paramsDescriptionType

amount

the amount

number

unit

the unit

string

patternIn

  • [optional] input format

  • ISO8601 by default

string

Examples

// with options = {
//   "lang": "fr",
//   "timezone": "Europe/Paris"
// }
'2017-05-10T15:57:23.769561+03:00':addD('3', 'day') // "2017-05-13T12:57:23.769Z"
'2017-05-10 15:57:23.769561+03:00':addD('3', 'month') // "2017-08-10T12:57:23.769Z"
'20160131':addD('3', 'day') // "2016-02-03T00:00:00.000Z"
'20160131':addD('3', 'month') // "2016-04-30T00:00:00.000Z"
'31-2016-01':addD('3', 'month', 'DD-YYYY-MM') // "2016-04-30T00:00:00.000Z"

subD( amount, unit, patternIn )

  • subtracts a time to a date

  • available units: day, week, month, quarter, year, hour, minute, second and millisecond

    • units are case insensitive, and support plural and short forms

ParametersDescriptionType

amount

the amount

number

unit

the unit

string

patternIn

  • [optional] input format

  • ISO8601 by default

string

Examples

// with options = {
//   "lang": "fr",
//   "timezone": "Europe/Paris"
// }
'2017-05-10T15:57:23.769561+03:00':subD('3', 'day') // "2017-05-07T12:57:23.769Z"
'2017-05-10 15:57:23.769561+03:00':subD('3', 'month') // "2017-02-10T12:57:23.769Z"
'20160131':subD('3', 'day') // "2016-01-28T00:00:00.000Z"
'20160131':subD('3', 'month') // "2015-10-31T00:00:00.000Z"
'31-2016-01':subD('3', 'month', 'DD-YYYY-MM') // "2015-10-31T00:00:00.000Z"

startOfD( unit, patternIn )

Creates a date and set it to the start of a unit of time.

ParametersDescriptionType

unit

the unit

string

patternIn

  • [optional] input format

  • ISO8601 by default

string

Examples

// with options = {
//   "lang": "fr",
//   "timezone": "Europe/Paris"
// }
'2017-05-10T15:57:23.769561+03:00':startOfD('day') // "2017-05-10T00:00:00.000Z"
'2017-05-10 15:57:23.769561+03:00':startOfD('month') // "2017-05-01T00:00:00.000Z"
'20160131':startOfD('day') // "2016-01-31T00:00:00.000Z"
'20160131':startOfD('month') // "2016-01-01T00:00:00.000Z"
'31-2016-01':startOfD('month', 'DD-YYYY-MM') // "2016-01-01T00:00:00.000Z"

endOfD( unit, patternIn )

Creates a date and set it to the end of a unit of time.

ParametersDescriptionType

unit

the unit

string

patternIn

  • [optional] input format

  • ISO8601 by default

string

Examples

// with options = {
//   "lang": "fr",
//   "timezone": "Europe/Paris"
// }
'2017-05-10T15:57:23.769561+03:00':endOfD('day') // "2017-05-10T23:59:59.999Z"
'2017-05-10 15:57:23.769561+03:00':endOfD('month') // "2017-05-31T23:59:59.999Z"
'20160131':endOfD('day') // "2016-01-31T23:59:59.999Z"
'20160131':endOfD('month') // "2016-01-31T23:59:59.999Z"
'31-2016-01':endOfD('month', 'DD-YYYY-MM') // "2016-01-31T23:59:59.999Z"

convDate( patternIn, patternOut )

Format dates

ParametersDescriptionType

patternIn

input format

string

patternOut

output format

string

Examples

// with options = {
//   "lang": "en",
//   "timezone": "Europe/Paris"
// }
'20160131':convDate('YYYYMMDD', 'L') // "01/31/2016"
'20160131':convDate('YYYYMMDD', 'LL') // "January 31, 2016"
'20160131':convDate('YYYYMMDD', 'LLLL') // "Sunday, January 31, 2016 1:00 AM"
'20160131':convDate('YYYYMMDD', 'dddd') // "Sunday"
1410715640:convDate('X', 'LLLL') // "Sunday, September 14, 2014 7:27 PM"
// with options = {
//   "lang": "fr",
//   "timezone": "Europe/Paris"
// }
'20160131':convDate('YYYYMMDD', 'LLLL') // "dimanche 31 janvier 2016 01:00"
'20160131':convDate('YYYYMMDD', 'dddd') // "dimanche"

Date formats

Date Formats DaysJS

FormatOutputDescription

X

1360013296

Unix Timestamp

x

1360013296123

Unix Millisecond Timestamp

YY

18

Two-digit year

YYYY

2018

Four-digit year

M

1-12

The month, beginning at 1

MM

01-12

The month, 2-digits

MMM

Jan-Dec

The abbreviated month name

MMMM

January-December

The full month name

D

1-31

The day of the month

DD

01-31

The day of the month, 2-digits

d

0-6

The day of the week, with Sunday as 0

dd

Su-Sa

The min name of the day of the week

ddd

Sun-Sat

The short name of the day of the week

dddd

Sunday-Saturday

The name of the day of the week

H

0-23

The hour

HH

00-23

The hour, 2-digits

h

1-12

The hour, 12-hour clock

hh

01-12

The hour, 12-hour clock, 2-digits

m

0-59

The minute

mm

00-59

The minute, 2-digits

s

0-59

The second

ss

00-59

The second, 2-digits

SSS

000-999

The millisecond, 3-digits

Z

+05:00

The offset from UTC, ±HH:mm

ZZ

+0500

The offset from UTC, ±HHmm

A

AM PM

a

am pm

List of localized formats

Because preferred formatting differs based on language, there are a few tokens that can be used to format a date based on report language.

There are upper and lower case variations on the same formats. The lowercase version is intended to be the shortened version of its uppercase counterpart.

FormatEnglish localeSample output

LT

h:mm A

8:02 PM

LTS

h:mm:ss A

8:02:18 PM

L

MM/DD/YYYY

08/16/2018

LL

MMMM D, YYYY

August 16, 2018

LLL

MMMM D, YYYY h:mm A

August 16, 2018 8:02 PM

LLLL

dddd, MMMM D, YYYY h:mm A

Thursday, August 16, 2018 8:02 PM

l

M/D/YYYY

8/16/2018

ll

MMM D, YYYY

Aug 16, 2018

lll

MMM D, YYYY h:mm A

Aug 16, 2018 8:02 PM

llll

ddd, MMM D, YYYY h:mm A

Thu, Aug 16, 2018 8:02 PM

Last updated