Amazon QuickSight – addDateTime
The ADD_DATETIME function in Amazon QuickSight allows you to add a specified interval to a date or time value. For example, you can add days, months, years, hours, minutes, or seconds to a date or time value.
Syntax
#Start# addDateTime(amount, period, datetime) #End#
Arguments
- amount: a numerical value representing the interval to add. For example, if you want to add 5 days to a date, amount would be 5.
- period: a string that specifies the unit of time to add. This can be “day”, “month”, “year”, “hour”, “minute”, or “second”.
Valid periods are as follows:
- YYYY: This returns the year portion of the date.
- Q: This returns the quarter that the date belongs to (1–4).
- MM: This returns the month portion of the date.
- DD: This returns the day portion of the date.
- WK: This returns the week portion of the date. The week starts on Sunday in Amazon QuickSight.
- HH: This returns the hour portion of the date.
- MI: This returns the minute portion of the date.
- SS: This returns the second portion of the date.
- MS: This returns the millisecond portion of the date.
- datetime: a date or time value to which the interval will be added. This can be a date or time literal, a column in a data set, or another calculated field.
Example
#Start# ADD_DATETIME("2022-01-01", "1", "day") #End#
This will add one day to the date “2022-01-01”, and the result will be “2022-01-02”.
You can use the ADD_DATETIME function to create calculated fields that you can use in visualizations or reports. For example, you could use this function to create a calculated field that shows the date one year from today. This can be useful for creating trend analyses or forecasting reports.