Fill in today's date, record when a form was signed, and calculate dates from other dates. Calculated Value scripts can use Moment.js, a date library available as moment. Custom Default Value scripts can't use moment; use JavaScript's built-in Date there.
Fill in today's date
To record the date a form was started, use a Custom Default Value, which runs once when the form opens:
-
Add a Text Field, for example Date Started. On its Display tab, select Disabled so users can't change it.
-
On the Data tab, expand Custom Default Value → JavaScript Default and enter:
JavaScriptvalue = new Date().toLocaleDateString('en-US', { year: 'numeric', month: '2-digit', day: '2-digit' });
This gives a date such as 10/23/2026. For a day-first date, replace 'en-US' with 'en-GB'. To use the format of each user's browser, use value = new Date().toLocaleDateString();
A default value is only set when the component is empty. When a saved submission is opened again, the original date is kept.
A Text Field also has a Current Date option on its Data tab, which needs no script. It updates every time the form is opened, so it shows the date the form was last opened rather than the date it was started. Use the script above when the original date matters.
Record the date a form was signed
Fill in a date when the user signs a Signature component, and keep it once set. The form has a Signature component signature and a disabled Text Field Date Signed (dateSigned).
On Date Signed, under Calculated Value → JavaScript Value, enter:
if (data.dateSigned) {
// Already recorded: keep the original date.
value = data.dateSigned;
} else if (data.signature) {
value = moment().format('MM/DD/YYYY');
} else {
value = '';
}
The date is filled in the first time the user signs, and doesn't change if the form is opened and saved again later.
Add business days to a date
Calculate a due date three business days after a date the user picks in a Date/Time component (startDate), skipping Saturdays and Sundays. As the calculated value of a Text Field:
var businessDaysToAdd = 3;
if (data.startDate) {
var due = moment(data.startDate);
var added = 0;
while (added < businessDaysToAdd) {
due.add(1, 'days');
// 0 is Sunday and 6 is Saturday.
if (due.day() !== 0 && due.day() !== 6) {
added++;
}
}
value = due.format('MM/DD/YYYY');
} else {
value = '';
}
For example, a start date of Friday 10/23/2026 gives a due date of Wednesday 10/28/2026. Change businessDaysToAdd to the number of days you need. Holidays are not skipped.
Count the days between two dates
For the number of days between startDate and endDate, as the calculated value of a Number component:
if (data.startDate && data.endDate) {
value = moment(data.endDate).diff(moment(data.startDate), 'days');
} else {
value = null;
}
Tips
-
Always check that a date has been entered before using it.
moment()of an empty value gives today's date or an invalid date, which can be misleading. -
Date/Time components save their value as a date and time in UTC, for example
2026-10-23T04:00:00.000Z. Usemoment(...)to read and format it rather than working with the text directly. -
For dates users enter by hand, the Date/Time and Day components validate the date for you. A Text Field with the input mask
99/99/9999is a simple alternative. -
For more ways to format and calculate dates, see the Moment.js documentation.