Skip to main content

getDate

This function formats a date object into ISO format (YYYY-MM-DD). If no date is provided, it returns today's date. The function can handle JavaScript Date objects and Moment.js date objects.

Syntax

app.getDate(date)

Parameters

ParameterTypeDescription
dateDate or moment(Optional) The date to format. If not provided, today's date will be used

Return Value

Returns a String containing the formatted date in ISO format (YYYY-MM-DD).

Examples

Example 1: Format the current date:

// Get today's date in ISO format
const formattedDate = app.getDate();
console.log(formattedDate); // e.g. "2025-04-16"

Example 2: Format a specific date:

// Format a specific date
const someDate = new Date(2025, 0, 15); // January 15, 2025
const formattedDate = app.getDate(someDate);
app.setFieldValue("contractStartDate", formattedDate); // Sets to "2025-01-15"

Example 3: Use with date calculations:

// Calculate and set a date 30 days from now
const futureDate = new Date();
futureDate.setDate(futureDate.getDate() + 30);
app.setFieldValue("expiryDate", app.getDate(futureDate));

Example 4: Work with dates from form fields:

// Get a date from a field and adjust it by 1 month
const startDate = new Date(app.getFieldValue("startDate"));
const newDate = new Date(startDate);
newDate.setMonth(newDate.getMonth() + 1);

// Format and set the end date
app.setFieldValue("endDate", app.getDate(newDate));
  • getToday() - For getting today's date in ISO format
  • getCalcDate() - For getting a date as a numeric value (days since epoch)
  • getCalcDateTime() - For getting a date and time as a numeric value
  • setFieldValue() - For setting date values in form controls

Notes

  • The function handles both JavaScript Date objects and Moment.js date objects
  • If the parameter is not provided, the function returns today's date (same as getToday())
  • The resulting date string follows ISO 8601 format (YYYY-MM-DD)
  • This format is suitable for database operations and string comparisons
  • When using with dates from form controls, ensure the input is a valid date object
  • Time information from the date object is discarded in the output string