Skip to content

Commit 1d06342

Browse files
committed
Update date-add.md
1 parent e4e8c69 commit 1d06342

File tree

1 file changed

+44
-18
lines changed
  • docs/en/sql-reference/20-sql-functions/05-datetime-functions

1 file changed

+44
-18
lines changed
Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,62 @@
11
---
22
title: DATE_ADD
33
---
4+
import FunctionDescription from '@site/src/components/FunctionDescription';
45

5-
Add the time interval or date interval to the provided date or date with time (timestamp/datetime).
6+
<FunctionDescription description="Introduced or updated: v1.2.641"/>
7+
8+
Adds a specified time interval to a DATE or TIMESTAMP value.
69

710
## Syntax
811

912
```sql
10-
DATE_ADD(<unit>, <value>, <date_or_time_expr>)
13+
DATE_ADD(<unit>, <interval>, <date_or_time_expr>)
1114
```
12-
## Arguments
1315

14-
| Arguments | Description |
15-
|-----------------------|-------------------------------------------------------------------------------------------------------------------|
16-
| `<unit>` | Must be of the following values: `YEAR`, `QUARTER`, `MONTH`, `DAY`, `HOUR`, `MINUTE` and `SECOND` |
17-
| `<value>` | This is the number of units of time that you want to add. For example, if you want to add 2 days, this will be 2. |
18-
| `<date_or_time_expr>` | A value of `DATE` or `TIMESTAMP` type |
16+
| Parameter | Description |
17+
|-----------------------|----------------------------------------------------------------------------------------------------|
18+
| `<unit>` | Specifies the time unit: `YEAR`, `QUARTER`, `MONTH`, `WEEK`, `DAY`, `HOUR`, `MINUTE` and `SECOND`. |
19+
| `<interval>` | The interval to add, e.g., 2 for 2 days if the unit is `DAY`. |
20+
| `<date_or_time_expr>` | A value of `DATE` or `TIMESTAMP` type. |
1921

2022
## Return Type
2123

22-
The function returns a value of the same type as the `<date_or_time_expr>` argument.
24+
DATE or TIMESTAMP (depending on the type of `<date_or_time_expr>`).
2325

2426
## Examples
2527

26-
Query:
28+
This example adds different time intervals (year, quarter, month, week, and day) to the current date:
29+
2730
```sql
28-
SELECT date_add(YEAR, 1, to_date('2018-01-02'));
29-
30-
┌──────────────────────────────────────────┐
31-
│ date_add(year, 1, to_date('2018-01-02')) │
32-
Date
33-
├──────────────────────────────────────────┤
34-
2019-01-02
35-
└──────────────────────────────────────────┘
31+
SELECT
32+
TODAY(),
33+
DATE_ADD(YEAR, 1, TODAY()),
34+
DATE_ADD(QUARTER, 1, TODAY()),
35+
DATE_ADD(MONTH, 1, TODAY()),
36+
DATE_ADD(WEEK, 1, TODAY()),
37+
DATE_ADD(DAY, 1, TODAY());
38+
39+
-[ RECORD 1 ]-----------------------------------
40+
today(): 2024-10-10
41+
DATE_ADD(YEAR, 1, today()): 2025-10-10
42+
DATE_ADD(QUARTER, 1, today()): 2025-01-10
43+
DATE_ADD(MONTH, 1, today()): 2024-11-10
44+
DATE_ADD(WEEK, 1, today()): 2024-10-17
45+
DATE_ADD(DAY, 1, today()): 2024-10-11
3646
```
47+
48+
This example adds different time intervals (hour, minute, and second) to the current timestamp:
49+
50+
```sql
51+
SELECT
52+
NOW(),
53+
DATE_ADD(HOUR, 1, NOW()),
54+
DATE_ADD(MINUTE, 1, NOW()),
55+
DATE_ADD(SECOND, 1, NOW());
56+
57+
-[ RECORD 1 ]-----------------------------------
58+
now(): 2024-10-10 01:35:33.601312
59+
DATE_ADD(HOUR, 1, now()): 2024-10-10 02:35:33.601312
60+
DATE_ADD(MINUTE, 1, now()): 2024-10-10 01:36:33.601312
61+
DATE_ADD(SECOND, 1, now()): 2024-10-10 01:35:34.601312
62+
```

0 commit comments

Comments
 (0)