Overview
Moment.js formulas let you manipulate stored Date Input values. You can reformat values, for example going from 2020/01/01 to January 1st, 2020. You can also add or subtract units of time, for example adding 7 days to a stored Date Input value.
Formatting Dates
Formatting formulas include tokens, like m, Do, or Y. These tokens represent a way to format your date information. To reformat stored Date Input values, use the following formula template: =moment(moment({Property ID/alias}),'format', '{tokens}'). For example =moment(moment(dateOne),'format', 'YY-MM-DD'). The following tables use Wednesday, January 9th, 1991 as a sample dateOne value.
You can also use field separators to visually chunk a date. Acceptable separators include the comma (,), forward slash (/), dash (-), period (.), or space ( ).
Presets
Token | Outcome | Possible Values |
---|---|---|
L | 01/09/1991 | 01-12 / 01-31 / [Year] |
l | 1/9/1991 | 1-12 / 1-31 / [Year] |
LL | January 9 1991 | January-December 1-31 [Year] |
ll | Jan 9 1991 | Jan-Dec 1-31 [Year] |
Day
Token | Outcome | Possible Values |
---|---|---|
D | 9 | 1 to 31 |
Do | 9th | 1st to 31st |
DD | 09 | 01 to 31 |
Day of the Week
Token | Outcome | Possible Values |
---|---|---|
d | 3 | 0 to 6 where Sunday = 0, and Saturday = 6 |
dd | We | Su to Sa |
ddd | Wed | Sun to Sat |
dddd | Wednesday | Sunday to Saturday |
Day of the Year
Token | Outcome | Possible Values |
---|---|---|
DDD | 9 | 1 to 365 |
DDDo | 9th | 1st to 365th |
DDDD | 009 | 001 to 365 |
Week of the Year
Token | Outcome | Possible Values |
---|---|---|
w | 2 | 1 to 53 |
wo | 2nd | 1st to 53rd |
ww | 02 | 01 to 53 |
Month
Token | Outcome | Possible Values |
---|---|---|
M | 1 | 1 to 12 |
Mo | 1st | 1st to 12th |
MM | 01 | 01 to 12 |
MMM | Jan | Jan to Dec |
MMMM | January | January to December |
Quarter
Token | Outcome | Possible Values |
---|---|---|
Q | 1 | 1 to 4 |
Qo | 1st | 1st to 4th |
Year
Token | Outcome | Possible Values |
---|---|---|
YY | 91 | 00-99 |
YYYY | 1991 | All years |
Manipulating Dates
To add or subtract units of time from stored Date Input values, use the following formula template: =moment(moment(moment({Property ID/alias}),'{add/subtract}',{number},'{unit(s) of time}'),'format','{tokens}'). For example: =moment(moment(moment(dateOne),'add',10,'days'),'format','YYYY-MM-DD'). The following tables, use the sample dateOne value of Wednesday, January 9th, 1991 (1991-01-09).
Add
Formula | Outcome |
---|---|
=moment(moment(moment(dateOne),'add',3,'days'),'format','YYYY-MM-DD') | 1991-01-12 |
=moment(moment(moment(dateOne),'add',2,'weeks'),'format','YYYY-MM-DD') | 1991-01-23 |
=moment(moment(moment(dateOne),'add',1,'month'),'format','YYYY-MM-DD') | 1991-02-09 |
Subtract
Formula | Outcome |
---|---|
=moment(moment(moment(dateOne),'subtract',3,'days'),'format','YYYY-MM-DD') | 1991-01-06 |
=moment(moment(moment(dateOne),'subtract',2,'weeks'')),'format','YYYY-MM-DD | 1990-12-26 |
=moment(moment(moment(dateOne),'subtract',1,'month'),'format','YYYY-MM-DD') | 1990-12-09 |
Time Zones
Unqork supports the tz function to set dates based on time zones. Unqork supports time zone data between the years of 1910 and 2090, which covers all years since US time zone data began in 1918. The formula fails if a time zone is applied to a date beyond 2090. If a formula fails, an error log is stored in the Express View DevTools Console log for troubleshooting purposes.
Some examples of timezone formulas include:
=MOMENT(MOMENT(A), 'isBefore', MOMENT(_arg))
=MOMENT(MOMENT(), 'format','[2.]x')
=MOMENT(MOMENT(MOMENT(MOMENT(), 'utc')), 'format', 'YYYY-MM-DDTHH:mm:ss.SSS')
Here is an example of using it in an Unqork formula. It can be nested like other moment functions
=moment(moment(moment(),'tz','America/Los_Angeles'),'format','yyyy-MM-DD HH:mm:ss z')
To learn more about using time zones in moment, view Moment.js documentation: https://momentjs.com/timezone/docs/