DateAdd
The DateAdd function adds or subtracts a specified amount of time from a date. You can specify the unit of time used to modify the date, such as years, months, or days.
You can use the DateAdd function to:
- Add or subtract time from a specific date
- Adjust the time for every date in a column with the date data type.
- Determine what date it was a specified number of days ago, or in the future
Syntax
DateAdd(unit, amount, date)
Function arguments:
| unit | (required) The unit of time to add (one of "year", "quarter", "month", "week", "day", "hour", "minute", or "second"). |
| amount | (required) The number of units to add. |
| date | (required) The date value or column of date values to which the function adds time. |
Usage notes
- The unit argument does not support columns.
- If the date or amount arguments are
Null, the function returnsNull. - If the amount argument is a number with a decimal, the function truncates it to its integer value, removing the decimal value.
- For example,
DateAdd("day", 1.9, Date("2020-01-01 12:00:00"))truncates the amount argument to1and adds one day to the specified date, returning2020-01-02 12:00:00.
- For example,
- If the unit argument is "month" and the date argument is a day that doesn't exist in the resulting month, the function returns the last day of that month.
- For example,
DateAdd("month", 1, Date("2020-01-31"))adds one month to the specified date and returns2020-02-29, the last day of February 2020.
- For example,
Examples
DateAdd("minute", 60, Date("1999-12-31 23:00:00"))
Adds 60 minutes to the specified date and returns 2000-01-01 00:00:00.
DateAdd("day", 1.9, Date("2020-01-01 12:00:00"))
Truncates the decimal portion of the amount argument to its integer value and adds one day to the specified date, returning 2020-01-02 12:00:00.
DateAdd("month", 1, Date("2020-01-31"))
Adds one month to the specified date and returns 2020-02-29.
DateAdd(“day”, 7, [Date])
Adds seven days to every date in the Date column.
DateAdd(“year”, -1, [Date])
Subtracts one year from every date in the Date column.
Updated 4 days ago
Related resources
