Skip to content

Commit 0e9f521

Browse files
authored
updates (#1844)
1 parent 3dcab32 commit 0e9f521

File tree

6 files changed

+167
-80
lines changed

6 files changed

+167
-80
lines changed

docs/en/sql-reference/20-sql-functions/05-datetime-functions/date-diff.md

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,56 @@ title: DATE_DIFF
33
---
44
import FunctionDescription from '@site/src/components/FunctionDescription';
55

6-
<FunctionDescription description="Introduced or updated: v1.2.645"/>
6+
<FunctionDescription description="Introduced or updated: v1.2.723"/>
77

88
Calculates the difference between two dates or timestamps based on a specified time unit. The result is positive if the `<end_date>` is after the `<start_date>`, and negative if it's before.
99

1010
## Syntax
1111

1212
```sql
13-
DATE_DIFF(<unit>, <start_date>, <end_date>)
13+
DATE_DIFF(
14+
YEAR | QUARTER | MONTH | WEEK | DAY | HOUR | MINUTE | SECOND |
15+
DOW | DOY | EPOCH | ISODOW | YEARWEEK | MILLENNIUM,
16+
<start_date_or_timestamp>,
17+
<end_date_or_timestamp>
18+
)
1419
```
1520

16-
| Parameter | Description |
17-
|----------------|-------------------------------------------------------------------------------------------------------------|
18-
| `<unit>` | The time unit for the difference: `YEAR`, `QUARTER`, `MONTH`, `WEEK`, `DAY`, `HOUR`, `MINUTE`, or `SECOND`. |
19-
| `<start_date>` | The starting date or timestamp. |
20-
| `<end_date>` | The ending date or timestamp. |
21+
| Keyword | Description |
22+
|--------------|-------------------------------------------------------------------------|
23+
| `DOW` | Day of the Week. Sunday (0) through Saturday (6). |
24+
| `DOY` | Day of the Year. 1 through 366. |
25+
| `EPOCH` | The number of seconds since 1970-01-01 00:00:00. |
26+
| `ISODOW` | ISO Day of the Week. Monday (1) through Sunday (7). |
27+
| `YEARWEEK` | The year and week number combined, following ISO 8601 (e.g., 202415). |
28+
| `MILLENNIUM` | The millennium of the date (1 for years 1–1000, 2 for 1001–2000, etc.). |
2129

2230
## Examples
2331

24-
This example calculates the difference in hours between **yesterday** and **today**:
32+
This example calculates the difference between a fixed timestamp (`2020-01-01 00:00:00`) and the current timestamp (`NOW()`), across various units such as year, ISO weekday, year-week, and millennium:
2533

2634
```sql
27-
SELECT DATE_DIFF(HOUR, YESTERDAY(), TODAY());
28-
29-
┌───────────────────────────────────────┐
30-
│ DATE_DIFF(HOUR, yesterday(), today()) │
31-
├───────────────────────────────────────┤
32-
24
33-
└───────────────────────────────────────┘
35+
SELECT
36+
DATE_DIFF(YEAR, TIMESTAMP '2020-01-01 00:00:00', NOW()) AS diff_year,
37+
DATE_DIFF(QUARTER, TIMESTAMP '2020-01-01 00:00:00', NOW()) AS diff_quarter,
38+
DATE_DIFF(MONTH, TIMESTAMP '2020-01-01 00:00:00', NOW()) AS diff_month,
39+
DATE_DIFF(WEEK, TIMESTAMP '2020-01-01 00:00:00', NOW()) AS diff_week,
40+
DATE_DIFF(DAY, TIMESTAMP '2020-01-01 00:00:00', NOW()) AS diff_day,
41+
DATE_DIFF(HOUR, TIMESTAMP '2020-01-01 00:00:00', NOW()) AS diff_hour,
42+
DATE_DIFF(MINUTE, TIMESTAMP '2020-01-01 00:00:00', NOW()) AS diff_minute,
43+
DATE_DIFF(SECOND, TIMESTAMP '2020-01-01 00:00:00', NOW()) AS diff_second,
44+
DATE_DIFF(DOW, TIMESTAMP '2020-01-01 00:00:00', NOW()) AS diff_dow,
45+
DATE_DIFF(DOY, TIMESTAMP '2020-01-01 00:00:00', NOW()) AS diff_doy,
46+
DATE_DIFF(EPOCH, TIMESTAMP '2020-01-01 00:00:00', NOW()) AS diff_epoch,
47+
DATE_DIFF(ISODOW, TIMESTAMP '2020-01-01 00:00:00', NOW()) AS diff_isodow,
48+
DATE_DIFF(YEARWEEK, TIMESTAMP '2020-01-01 00:00:00', NOW()) AS diff_yearweek,
49+
DATE_DIFF(MILLENNIUM, TIMESTAMP '2020-01-01 00:00:00', NOW()) AS diff_millennium;
3450
```
3551

36-
This example calculates the difference in years between the current date and January 1, 2000;
37-
3852
```sql
39-
SELECT NOW(), DATE_DIFF(YEAR, NOW(), TO_DATE('2000-01-01'));
40-
41-
┌────────────────────────────────────────────────────────────────────────────┐
42-
│ now() │ DATE_DIFF(YEAR, now(), to_date('2000-01-01')) │
43-
├────────────────────────────┼───────────────────────────────────────────────┤
44-
2024-10-15 03:38:23.726599-24
45-
└────────────────────────────────────────────────────────────────────────────┘
53+
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
54+
│ diff_year │ diff_quarter │ diff_month │ diff_week │ diff_day │ diff_hour │ diff_minute │ diff_second │ diff_dow │ diff_doy │ diff_epoch │ diff_isodow │ diff_yearweek │ diff_millennium │
55+
├───────────┼──────────────┼────────────┼───────────┼──────────┼───────────┼─────────────┼─────────────┼──────────┼──────────┼────────────┼─────────────┼───────────────┼─────────────────┤
56+
5216327619324638627831841669910691932193216699106919325150
57+
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
4658
```

docs/en/sql-reference/20-sql-functions/05-datetime-functions/date-part.md

Lines changed: 39 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,66 +4,61 @@ title: DATE_PART
44

55
import FunctionDescription from '@site/src/components/FunctionDescription';
66

7-
<FunctionDescription description="Introduced or updated: v1.2.153"/>
7+
<FunctionDescription description="Introduced or updated: v1.2.723"/>
88

9-
Retrieves the designated portion of a date, time, or timestamp.
9+
Retrieves the designated portion of a date or timestamp.
1010

1111
See also: [EXTRACT](extract.md)
1212

1313
## Syntax
1414

1515
```sql
16-
DATE_PART( YEAR | QUARTER | MONTH | WEEK | DAY | HOUR | MINUTE | SECOND | DOW | DOY, <date_or_time_expr> )
16+
DATE_PART(
17+
YEAR | QUARTER | MONTH | WEEK | DAY | HOUR | MINUTE | SECOND |
18+
DOW | DOY | EPOCH | ISODOW | YEARWEEK | MILLENNIUM,
19+
<date_or_timestamp_expr>
20+
)
1721
```
1822

19-
- DOW: Day of Week.
20-
- DOY: Day of Year.
23+
| Keyword | Description |
24+
|--------------|-------------------------------------------------------------------------|
25+
| `DOW` | Day of the Week. Sunday (0) through Saturday (6). |
26+
| `DOY` | Day of the Year. 1 through 366. |
27+
| `EPOCH` | The number of seconds since 1970-01-01 00:00:00. |
28+
| `ISODOW` | ISO Day of the Week. Monday (1) through Sunday (7). |
29+
| `YEARWEEK` | The year and week number combined, following ISO 8601 (e.g., 202415). |
30+
| `MILLENNIUM` | The millennium of the date (1 for years 1–1000, 2 for 1001–2000, etc.). |
2131

2232
## Return Type
2333

2434
Integer.
2535

2636
## Examples
2737

28-
```sql
29-
SELECT NOW();
30-
31-
┌────────────────────────────┐
32-
│ now() │
33-
├────────────────────────────┤
34-
2024-05-22 02:55:52.954761
35-
└────────────────────────────┘
36-
37-
SELECT DATE_PART(DAY, NOW());
38-
39-
┌───────────────────────┐
40-
│ date_part(day, now()) │
41-
├───────────────────────┤
42-
22
43-
└───────────────────────┘
44-
45-
SELECT DATE_PART(DOW, NOW());
46-
47-
┌───────────────────────┐
48-
│ date_part(dow, now()) │
49-
├───────────────────────┤
50-
3
51-
└───────────────────────┘
38+
This example demonstrates how to use DATE_PART to extract various components—such as year, month, ISO week day, year-week combination, and millennium—from the current timestamp:
5239

53-
SELECT DATE_PART(DOY, NOW());
54-
55-
┌───────────────────────┐
56-
│ date_part(doy, now()) │
57-
├───────────────────────┤
58-
143
59-
└───────────────────────┘
60-
61-
SELECT DATE_PART(MONTH, TO_DATE('2024-05-21'));
40+
```sql
41+
SELECT
42+
DATE_PART(YEAR, NOW()) AS year_part,
43+
DATE_PART(QUARTER, NOW()) AS quarter_part,
44+
DATE_PART(MONTH, NOW()) AS month_part,
45+
DATE_PART(WEEK, NOW()) AS week_part,
46+
DATE_PART(DAY, NOW()) AS day_part,
47+
DATE_PART(HOUR, NOW()) AS hour_part,
48+
DATE_PART(MINUTE, NOW()) AS minute_part,
49+
DATE_PART(SECOND, NOW()) AS second_part,
50+
DATE_PART(DOW, NOW()) AS dow_part,
51+
DATE_PART(DOY, NOW()) AS doy_part,
52+
DATE_PART(EPOCH, NOW()) AS epoch_part,
53+
DATE_PART(ISODOW, NOW()) AS isodow_part,
54+
DATE_PART(YEARWEEK, NOW()) AS yearweek_part,
55+
DATE_PART(MILLENNIUM, NOW()) AS millennium_part;
56+
```
6257

63-
┌─────────────────────────────────────────┐
64-
│ date_part(month, to_date('2024-05-21')) │
65-
UInt8
66-
├─────────────────────────────────────────┤
67-
5
68-
└─────────────────────────────────────────┘
58+
```sql
59+
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
60+
year_part │ quarter_part │ month_part │ week_part │ day_part │ hour_part │ minute_part │ second_part │ dow_part │ doy_part │ epoch_part │ isodow_part │ yearweek_part │ millennium_part
61+
├─────────────────────────┼────────────┼───────────┼──────────┼───────────┼─────────────┼─────────────┼──────────┼──────────┼───────────────────┼─────────────┼───────────────┼─────────────────┤
62+
2025 2 4 161618101031061744827010.25767132025163
63+
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
6964
```

docs/en/sql-reference/20-sql-functions/05-datetime-functions/extract.md

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: EXTRACT
44

55
import FunctionDescription from '@site/src/components/FunctionDescription';
66

7-
<FunctionDescription description="Introduced or updated: v1.2.697"/>
7+
<FunctionDescription description="Introduced or updated: v1.2.723"/>
88

99
Retrieves the designated portion of a date, timestamp, or interval.
1010

@@ -14,15 +14,24 @@ See also: [DATE_PART](date-part.md)
1414

1515
```sql
1616
-- Extract from a date or timestamp
17-
EXTRACT( YEAR | QUARTER | MONTH | WEEK | DAY | HOUR | MINUTE | SECOND | DOW | DOY | EPOCH FROM <date_or_timestamp> )
17+
EXTRACT(
18+
YEAR | QUARTER | MONTH | WEEK | DAY | HOUR | MINUTE | SECOND |
19+
DOW | DOY | EPOCH | ISODOW | YEARWEEK | MILLENNIUM
20+
FROM <date_or_timestamp>
21+
)
1822

1923
-- Extract from an interval
2024
EXTRACT( YEAR | MONTH | WEEK | DAY | HOUR | MINUTE | SECOND | MICROSECOND | EPOCH FROM <interval> )
2125
```
2226

23-
- `DOW`: Day of the Week.
24-
- `DOY`: Day of the Year.
25-
- `EPOCH`: The number of seconds since 1970-01-01 00:00:00.
27+
| Keyword | Description |
28+
|--------------|-------------------------------------------------------------------------|
29+
| `DOW` | Day of the Week. Sunday (0) through Saturday (6). |
30+
| `DOY` | Day of the Year. 1 through 366. |
31+
| `EPOCH` | The number of seconds since 1970-01-01 00:00:00. |
32+
| `ISODOW` | ISO Day of the Week. Monday (1) through Sunday (7). |
33+
| `YEARWEEK` | The year and week number combined, following ISO 8601 (e.g., 202415). |
34+
| `MILLENNIUM` | The millennium of the date (1 for years 1–1000, 2 for 1001–2000, etc.). |
2635

2736
## Return Type
2837

@@ -46,13 +55,20 @@ The return type depends on the field being extracted:
4655
This example extracts various fields from the current timestamp:
4756

4857
```sql
49-
SELECT NOW(), EXTRACT(DAY FROM NOW()), EXTRACT(DOY FROM NOW()), EXTRACT(EPOCH FROM NOW());
50-
51-
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
52-
│ now() │ EXTRACT(DAY FROM now()) │ EXTRACT(DOY FROM now()) │ EXTRACT(EPOCH FROM now()) │
53-
├────────────────────────────┼─────────────────────────┼─────────────────────────┼───────────────────────────┤
54-
│ 2025-02-08 03:51:51.991167 │ 8 │ 39 │ 1738986711.991167 │
55-
└────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
58+
SELECT
59+
NOW(),
60+
EXTRACT(DAY FROM NOW()),
61+
EXTRACT(DOY FROM NOW()),
62+
EXTRACT(EPOCH FROM NOW()),
63+
EXTRACT(ISODOW FROM NOW()),
64+
EXTRACT(YEARWEEK FROM NOW()),
65+
EXTRACT(MILLENNIUM FROM NOW());
66+
67+
┌─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
68+
│ now() │ EXTRACT(DAY FROM now()) │ EXTRACT(DOY FROM now()) │ EXTRACT(EPOCH FROM now()) │ EXTRACT(ISODOW FROM now()) │ EXTRACT(YEARWEEK FROM now()) │ EXTRACT(MILLENNIUM FROM now()) │
69+
├────────────────────────────┼─────────────────────────┼─────────────────────────┼───────────────────────────┼────────────────────────────┼──────────────────────────────┼────────────────────────────────┤
70+
│ 2025-04-16 18:04:22.773888 │ 16 │ 106 │ 1744826662.773888 │ 3 │ 202516 │ 3 │
71+
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
5672
```
5773

5874
This example extracts the number of days from an interval:

docs/en/sql-reference/20-sql-functions/05-datetime-functions/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ This section provides reference information for the datetime-related functions i
4646
- [TO_YYYYMMDD](to-yyyymmdd)
4747
- [TO_YYYYMMDDHH](to-yyyymmddhh)
4848
- [TO_YYYYMMDDHHMMSS](to-yyyymmddhhmmss)
49+
- [MILLENNIUM](millennium.md)
50+
- [YEARWEEK](yearweek.md)
4951

5052
## Date Arithmetic Functions
5153

0 commit comments

Comments
 (0)