What is DATEADD function in Tableau
The DATEADD in Tableau is used to add a specific amount of time to a date or datetime value. It takes three arguments: the time unit to add, the amount of time to add, and the starting date or datetime value.
The syntax for using the DATEADD function in Tableau is as follows:
DATEADD(interval, number, date)
Syntax explanation:
- Interval is the unit of time that you want to add to the date. This can be one of the following: ‘day’, ‘week’, ‘month’, ‘quarter’, ‘year’, ‘hour’, ‘minute’, ‘second’, ‘millisecond’, or ‘microsecond’.
- Interval is the case sensitive, it should be always in lower case.
- Number is the number of intervals that you want to add to the date.
- Date is the date or datetime field to which you want to add the specified interval.
Some key features for DATEADD in Tableau
- The first argument specifies the time unit to add, such as ‘day’, ‘week’, ‘month’, ‘quarter’, ‘year’, ‘hour’, ‘minute’, or ‘second’.
- The second argument is the amount of time to add, specified as a positive or negative integer.
- The third argument is the starting date or datetime value.
You can also use this DATEDADD function inside any other function like CASE function and also can be use with other cart in tableau like
Lets take 5 examples of using the DATEADD() function in Tableau to explain and understand more in details
Examples #1: DATEADD in Tableau to add 7 days to a date
Below is the example with specific date just for understanding for you
DATEADD('day', 7, #2022-02-10#)
This returns a new date of February 17, 2022.
Now try the same with Ship date , it will add 7 days to date and create new date for Ship date in dataset. as shown below
DATEADD('day', 7, [Ship Date])
Below is the example of output in image which shows how the 7 Days is added to Ship date in dataset.
Examples #2: Subtract 3 months from a date
Below is the example with specific date just for understanding for you how it will look if add months.
DATEADD('month', 3, #2022-05-15#)
This returns a new date of Aug 15, 2022.
Now try the same with Ship date , it will add 7 days to date and create new date for Ship date in dataset. as shown below
DATEADD('month', 3, [Ship Date])
Below is the example of output in image which shows how the 7 Days is added to Ship date in dataset.
Examples #3: Add 1 year to a date
Below is the example with specific date just for understanding for you
DATEADD('year', 1, #2022-02-15#)
This returns a new date of February 15, 2023.
Now try the same with Ship date , it will add 7 days to date and create new date for Ship date in dataset. as shown below
DATEADD('year', 1, [Ship Date])
Below is the example of output in image which shows how the 7 Days is added to Ship date in dataset.
Examples #4: Add 15 minutes to a datetime
DATEADD('minute', 15, #2022-02-15 10:30:00#)
This returns a new datetime of February 15, 2022 10:45:00 AM.
Examples #5: Add 2 hours to a datetime
Below is the example with specific date just for understanding for you
DATEADD('hour', 2, #2022-02-15 10:30:00#)
This returns a new datetime of February 15, 2022 12:30:00 PM.
In each example, the DATEADD() function adds a specific amount of time to a date or datetime value, and returns a new date or datetime value. The resulting value can be used in calculations or displayed in a visualization.