How to add or subtract from a date
These Calculated Field expressions move a date forward or back. Replace fieldAliasGoesHere with the alias of your date Field.
Each snippet ends with .toDate(). A Calculated Field keeps the value its expression returns, and a Moment.js object does not come through as a date on its own. Converting it back to a JavaScript date keeps the new Field a date.
Adding to a date
Uses Moment.js add().
// Date: August 6, 2022
// Result: August 10, 2022
var date = $record['fieldAliasGoesHere'];
var adjustedDate = moment(date).add(4, 'days').toDate();
adjustedDate;
Subtracting from a date
Uses Moment.js subtract().
// Date: August 6, 2022
// Result: August 3, 2022
var date = $record['fieldAliasGoesHere'];
var adjustedDate = moment(date).subtract(3, 'days').toDate();
adjustedDate;
Both functions take other units in place of 'days', such as 'weeks', 'months', and 'years'.