getEndOfMonth
This function calculates and returns the last day of the month for a given date. It's useful for financial calculations, period-end processing, and determining date ranges.
Syntax
app.getEndOfMonth(dateParam)
Parameters
Parameter | Type | Description |
---|---|---|
dateParam | Date, String, or Object | The date for which to find the last day of the month. Can be a JavaScript Date object, an ISO date string, or an object that can be converted to a date |
Return Value
Returns a String representing the last day of the month in ISO format (YYYY-MM-DD).
Examples
Example 1: Get the end date of the current month:
// Get the last day of the current month
const today = new Date();
const endOfMonth = app.getEndOfMonth(today);
app.setFieldValue("monthEndDate", endOfMonth);
Example 2: Calculate payment due date (end of next month):
// Calculate the payment due date as the end of next month
const invoiceDate = app.getFieldValue("invoiceDate");
const invoiceDateObj = new Date(invoiceDate);
invoiceDateObj.setMonth(invoiceDateObj.getMonth() + 1);
const paymentDueDate = app.getEndOfMonth(invoiceDateObj);
app.setFieldValue("paymentDueDate", paymentDueDate);
Example 3: Creating a monthly report range:
// Set up a monthly report range
const reportMonth = new Date(app.getFieldValue("reportMonth"));
const firstOfMonth = app.getDate(new Date(reportMonth.getFullYear(), reportMonth.getMonth(), 1));
const lastOfMonth = app.getEndOfMonth(reportMonth);
app.setFieldValue("reportStartDate", firstOfMonth);
app.setFieldValue("reportEndDate", lastOfMonth);
Example 4: Calculate monthly recurring dates:
// Calculate recurring billing dates for the next 3 months
const currentDate = new Date();
const billingDates = [];
for (let i = 0; i < 3; i++) {
const futureDate = new Date(currentDate);
futureDate.setMonth(currentDate.getMonth() + i);
billingDates.push(app.getEndOfMonth(futureDate));
}
console.log("Future billing dates:", billingDates);
// e.g. ["2025-04-30", "2025-05-31", "2025-06-30"]
Related Functions
getDate()
- For formatting a date object as a stringgetToday()
- For getting today's date as a stringgetCalcDate()
- For date-based calculations
Notes
- The function handles leap years correctly when determining the end of February
- The result is always in ISO format (YYYY-MM-DD), suitable for database operations
- The function works with dates from any time zone
- If the input date is invalid, the function may return unexpected results
- This function is particularly useful for financial operations that work with month-end dates
- You can combine this function with date arithmetic to find end dates of future or past months