dateadd1
The dateadd1 function is used to modify the date value by the specified delta according to the specified unit datepart.
To obtain a date with a specified offset from the current date, it can be used together with current_date or getdate.
Syntax
dateadd1(string date, bigint delta, string datepart)
Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| date | Yes | DATE or STRING | The start date. Supports the following formats:
|
| delta | Yes | BIGINT | The modification magnitude. |
| datepart | Yes | STRING | The time unit for modification. The datepart parameter supports extended date formats: year, month or mon, day, and hour.
|
Return Values
Returns a date value of type STRING.
- If date is not of type DATE or STRING, an error is returned with the message "data type mismatch".
- If date is of type DATE or STRING but does not conform to the input format for date values, NULL is returned.
- If the date value is NULL, NULL is returned.
- If the delta or datepart value is NULL, NULL is returned.
Example Code
Returns 2023-08-15 17:00:00 after one day is added.
select dateadd1( '2023-08-14 17:00:00', 1, 'dd');
Returns 2025-04-14 17:00:00 after 20 months are added. Month overflow causes the year to increase by 2.
select dateadd1('2023-08-14 17:00:00', 20, 'mm'); Returns 2023-09-14 17:00:00.
select dateadd1('2023-08-14 17:00:00', 1, 'mm'); Returns 2023-09-14.
select dateadd1('2023-08-14', 1, 'mm'); Assuming the current time is 2023-08-14 17:00:00, returns 2023-08-13 17:00:00.
select dateadd1(getdate(),-1,'dd');
Returns NULL.
select dateadd1(date '2023-08-14', 1, null);
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot