In certain pricing or contract scenarios, it's necessary to restrict selected start or end dates so they always align with the first day of a calendar month. This approach ensures consistency across billing cycles and simplifies downstream logic tied to monthly intervals. The following method explains how to configure this behavior using calculated date logic.
How to Set Up the Base Date and User Input
Begin by creating two date questions:
- One date question that acts as the base date. This should always be a fixed value—such as January 1, 2025—and represents the anchor point for all date calculations.
- Another date question that is visible to the user, allowing them to select any date.
Once a user selects a date, extract the month and year from that input.
How to Calculate the Time Difference
Next, determine the difference in time between the base date and the selected date. Since the base year is fixed, you can simplify your logic by hardcoding it when calculating the year difference.
Use the Add_Months() function to add the calculated number of months to the base date.
Note: This function will return a date that is one day before the equivalent date in the following month.
Example: If the base date is 1/1/2024 and you add 12 months, the result will be 31/12/2024 (not 1/1/2025).
Then, use the Add_Years() function if the selected date is in a different year than the base year.
Again, the result will fall one day before the equivalent date in the next year.
Continuing the example: Adding a year to 31/12/2024 will result in 30/12/2024.
How to Shift the Date to the First of the Month
At this point, your calculated date will be the last day of the intended month. To convert it into the first day of that month, do the following:
- Extract the day number from the calculated date.
- Subtract that number from the date to reach the last day of the previous month.
- Add one day to get to the first day of the target month.
This adjustment ensures the final calculated date always aligns with the first of the month, regardless of which date the user originally selected.
How to Use This Configuration in Sales Mode
In Sales Mode, this logic allows you to enforce alignment with billing cycles that begin on the first day of each month. Quotes that rely on monthly durations or usage calculations benefit from this consistency, and sellers are not required to manually adjust the date input.