Help Centre › Functions & Formulas
For a full list of available calculation functions, please read What calculation functions are supported.
Description
The DATESUB function is a handy tool for calculating dates that occur a certain number of days before a specified start date.
Syntax
date_sub(startDate, numDays)
Arguments
- startDate: This is the starting point, a date from which you want to go back. You input this as a DATE function expression, like '2020-01-01' for the 1st of January, 2020.
- numDays: This is the number of days you want to go back from your start date. It’s an INT function expression. So, if you put 10, it means 10 days before the start date.
Remarks
- What It Does: It calculates the date that occurs 'numDays' before 'startDate'. For example, DATESUB('2021-03-10', 5) would give you '2021-03-05' – 5 days before March 10, 2021.
- Handling Negative Numbers: If 'numDays' is negative, the function adds the absolute value of 'numDays' to 'startDate'. So, DATESUB('2021-03-10', -5) would move you forward to '2021-03-15'.
- Range Overflow: If the calculated date falls outside the valid date range, the function will give an error. This prevents you from accidentally ending up with an impossible date.
Example
| Formula | Description | Result |
| =DATESUB('2016-07-30', 1) | Subtracts 1 day from the current date | 2016-07-29 |
| =DATESUB('2016-07-30', -1) | Subtracts -1 day (thus adds 1 day) from the current date | 2016-07-31 |
Errors
For a full list of formula errors, please read Formula errors.