Date Time Functions
Overview
Date Time Functions:
This module helps to get Next Month's start and end date, Previous Month start and end date, Current week in a month, Month of the year, No. of weeks in a month, week of year and working days(Business Days) between dates.
Days:
- NoOfDaysinMonth
Months:
- NextMonthStartDate
- NextMonthEndDate
- PreviousMonthStartDate
- PreviousMonthEndDate
- MonthStartDate
- MonthEndDate
Weeks:
- CurrentWeekinMonth
- NoOfWeeksinMonth
- TotalWeeksinYear
Business Days:
- GetBusinessDays
Documentation
Typical usage scenario
Date Time Functions provides ready-made date calculations that Mendix expressions do not cover out of the box, so you do not have to hand-write the same JavaScript in every app.
Use it when you need to:
- Build reporting and dashboard filters — resolve "this month", "last month", or "next month" into concrete start and end dates to drive XPath constraints and date range filters.
- Calculate lead times and SLAs in working days — measure the number of business days between two dates while excluding weekends, for order fulfilment, ticket resolution, or approval deadlines.
- Default date fields on a form — pre-fill period start and end dates on timesheets, invoices, payroll runs, and expense claims.
- Drive planning and scheduling screens — show which week of the month the user is in, how many weeks a given month spans, or how many weeks a year contains (52 or 53).
- Validate or paginate by month — get the number of days in any month to build calendar grids or bound a day-of-month input.
The module is aimed at any app that works with monthly or weekly periods, and is especially useful in reporting, HR, finance, and field-service applications.
Features and limitations
The module contains 11 client-side JavaScript actions, grouped into four folders. month is always 1-based (1 = January).
Days
- GetNoOfDaysInMonth — parameters: year, month (Integer/Long). Returns Integer/Long: the number of days in that month.
Months
- MonthStartDate — parameters: year, month (Integer/Long). Returns Date and time: the first day of that month.
- MonthEndDate — parameters: year, month (Integer/Long). Returns Date and time: the last day of that month.
- NextMonthStartDate — no parameters. Returns Date and time: the first day of next month.
- NextMonthEndDate — no parameters. Returns Date and time: the last day of next month.
- PreviousMonthStartDate — no parameters. Returns Date and time: the first day of last month.
- PreviousMonthEndDate — no parameters. Returns Date and time: the last day of last month.
Weeks
- CurrentWeekinMonth — no parameters. Returns Integer/Long: which week of the current month today falls in.
- NoOfWeeksinMonth — parameters: year, month (Integer/Long). Returns Integer/Long: the number of calendar weeks the month spans.
- TotalWeeksinYear — parameter: year (Integer/Long). Returns Integer/Long: the total ISO weeks in that year (52 or 53).
Business Days
- GetBusinessDays — parameters: fromDate, toDate (String, in MM/dd/yyyy format). Returns Integer/Long: the working days between the two dates, excluding Saturday and Sunday.
Dependencies
- Mendix Studio Pro 10.24.17 or higher.
No other Marketplace modules, Java libraries, or third-party services are required.
Installation
1. In Studio Pro, open your app and go to Marketplace > Import module package, or download the module package and use App > Import module package.
2. Select Date Time Functions and import it into your app.
3. The module is added as DateTimeFunctions, with the JavaScript actions organized into the Days, Months, Weeks, and Business Days folders.
Configuration
No configuration is required — there are no constants, scheduled events, or settings to change.
To use an action, add a JavaScript action call activity to a nanoflow, pick the action from the DateTimeFunctions module, supply any parameters, and store the result in a variable.
If your app uses module security, grant the relevant user roles access to the module so the actions can be called.
---
Known bugs
None.
If you find an issue, please report it on the GitHub repository.
---
Frequently Asked Questions
Can I use these actions in a microflow?
No. JavaScript actions run in the client, so they are only available in nanoflows. Call the action in a nanoflow and pass the result into a microflow if you need it server-side.
Why does GetBusinessDays return 0 or an unexpected number?
Almost always a parameter format problem. Both parameters must be strings in MM/dd/yyyy format — use formatDateTime($yourDate, 'MM/dd/yyyy'). Also note that a toDate earlier than fromDate returns 0 by design.
Does GetBusinessDays account for public holidays?
No. Only Saturdays and Sundays are excluded. Subtract holidays yourself if your process requires it.
Is month 0-based like in JavaScript?
No. All actions take month as 1-based, so January is 1 and December is 12.
Why do the no-parameter actions sometimes return a different day than I expect?
They calculate from the end user's device clock and time zone. If your app needs server-consistent results, derive the date server-side and pass explicit year and month values into MonthStartDate or MonthEndDate instead.
Does this module add anything to my database?
No. It contains only JavaScript actions — there are no entities and no domain model changes.
Releases
**Date Time Functions:**
This module helps to get Next Month's start and end date, Previous Month start and end date, Current week in a month, Month of the year, No. of weeks in a month, week of year and working days(Business Days) between dates.
**Days:**
• **NoOfDaysinMonth**:
Get total number of days in month using year and month value.
**Months**:
• **NextMonthStartDate**:
Get the Next month Start date.
• **NextMonthEndDate**:
Get the Next month End date.
• **PreviousMonthStartDate**:
Get the Previous month Start date.
• **PreviousMonthEndDate**:
Get the Previous month End date.
• **MonthStartDate**:
Get Month Start date using year and month value.
• **MonthEndDate**:
Get Month End date using year and month value.
Weeks:
• **CurrentWeekinMonth**:
Get the current week of the month.
• **NoOfWeeksinMonth**:
Get total number of weeks in a Month.
• **TotalWeeksinYear**:
Get the total weeks in year using year value.
**Business Days:**
• **GetBusinessDays**:
Get working days (excluding Saturday and Sunday) using start date and end date.
**Dependencies**
• Mendix modeler 10.24.17.
**Screenshots:**
