Manipulating Dates with Moment.js
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 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 |
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).
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 Express View is how your end-user views your application. Express View also lets you preview your applications to test your configuration and view the styling. This is also the view your end-users will see when interacting with your application. After configuring a module, click Preview in the Module Builder to interact with the module in Express View. DevTools Console The DevTools Console helps you securely store, build, test, and deploy your software. 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/