--- title: "Date Math in Calculation Formulas" slug: "date-math-in-calculation-formulas" status: "new" updated: 2026-07-21T20:18:37Z published: 2026-07-21T20:18:37Z canonical: "knowledge.technolutions.net/date-math-in-calculation-formulas" stale: true --- > ## Documentation Index > Fetch the complete documentation index at: https://knowledge.technolutions.net/llms.txt > Use this file to discover all available pages before exploring further. # Date Math in Calculation Formulas Calculation formulas on forms can use JavaScript date methods to add time to a date or calculate the difference between two dates. These examples assume that the referenced form fields are configured as date fields and have export keys available to the calculation. > [!TIP] > ⭐ Get Inspired > > This article was adapted from [a post by Technolutions staff](https://community.technolutions.net/get-inspired/post/date-math-in-calculation-formulas-gVidRwpizfDHZ77) in the Slate Community Forums' Get Inspired space. Have a great idea for a Get Inspired post? [Let us know](https://community.technolutions.net/get-inspired/new?post_type=gnHx7As1gZ8r6Ld)! ## Add one year to a date Use the following pattern to add one year to a date and return the result in `yyyyMMdd` format. Replace `date_export_key` with the export key of your date field. ```Formula (@date_export_key.getFullYear() + 1) + ('0' + (@date_export_key.getMonth() + 1)).slice(-2) + ('0' + @date_export_key.getDate()).slice(-2) ``` The formula uses: - `getFullYear()` to return the four-digit year. - `getMonth()` to return the month. JavaScript months are zero-indexed, so the formula adds `1`. - `getDate()` to return the day of the month. - `.slice(-2)` to keep month and day values two digits long. ## Calculate the difference between two dates JavaScript stores the difference between dates in milliseconds. Divide the date difference by the appropriate number of milliseconds for the desired unit. ### Days ```Formula Math.floor((@date1 - @date2) / 86400000) ``` ### Weeks ```Formula Math.floor((@date1 - @date2) / 604800000) ``` ### Years ```Formula Math.floor((@date1 - @date2) / 31557600000) ``` > [!WARNING] > 📝 Note > > The year example uses 365.25 days to account for leap years. Month calculations are not included because month lengths vary. ## Test the output 1. Preview the form with sample date values. 2. Confirm that the calculation updates when the source date changes. 3. Submit a test record and verify the stored value in the form response. 📖 Learn more about [JavaScript date methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date).