Skip to content

Commit f3da99e

Browse files
authored
Update extract.md (#1607)
1 parent 43ba00c commit f3da99e

File tree

1 file changed

+26
-45
lines changed
  • docs/en/sql-reference/20-sql-functions/05-datetime-functions

1 file changed

+26
-45
lines changed

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

Lines changed: 26 additions & 45 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.153"/>
7+
<FunctionDescription description="Introduced or updated: v1.2.692"/>
88

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

@@ -13,57 +13,38 @@ See also: [DATE_PART](date-part.md)
1313
## Syntax
1414

1515
```sql
16-
EXTRACT( YEAR | QUARTER | MONTH | WEEK | DAY | HOUR | MINUTE | SECOND | DOW | DOY FROM <date_or_time_expr> )
16+
EXTRACT( YEAR | QUARTER | MONTH | WEEK | DAY | HOUR | MINUTE | SECOND | DOW | DOY | EPOCH FROM <date_or_time_expr> )
1717
```
1818

19-
- DOW: Day of the Week.
20-
- DOY: Day of Year.
19+
- `DOW`: Day of the Week.
20+
- `DOY`: Day of the Year.
21+
- `EPOCH`: The number of seconds since 1970-01-01 00:00:00.
2122

2223
## Return Type
2324

24-
Integer.
25+
The return type depends on the field being extracted:
26+
27+
- Returns Integer: When extracting discrete date or time components (e.g., YEAR, MONTH, DAY, DOY, HOUR, MINUTE, SECOND), the function returns an Integer.
28+
29+
```sql
30+
SELECT EXTRACT(DAY FROM now()); -- Returns Integer
31+
SELECT EXTRACT(DOY FROM now()); -- Returns Integer
32+
```
33+
34+
- Returns Float: When extracting EPOCH (the number of seconds since 1970-01-01 00:00:00 UTC), the function returns a Float, as it may include fractional seconds.
35+
36+
```sql
37+
SELECT EXTRACT(EPOCH FROM now()); -- Returns Float
38+
```
2539

2640
## Examples
2741

2842
```sql
29-
SELECT NOW();
30-
31-
┌────────────────────────────┐
32-
│ now() │
33-
├────────────────────────────┤
34-
2024-05-22 03:00:35.977589
35-
└────────────────────────────┘
36-
37-
SELECT EXTRACT(DAY FROM NOW());
38-
39-
┌─────────────────────────┐
40-
│ extract(day from now()) │
41-
├─────────────────────────┤
42-
22
43-
└─────────────────────────┘
44-
45-
SELECT EXTRACT(DOW FROM NOW());
46-
47-
┌─────────────────────────┐
48-
│ extract(dow from now()) │
49-
├─────────────────────────┤
50-
3
51-
└─────────────────────────┘
52-
53-
SELECT EXTRACT(DOY FROM NOW());
54-
55-
┌─────────────────────────┐
56-
│ extract(doy from now()) │
57-
├─────────────────────────┤
58-
143
59-
└─────────────────────────┘
60-
61-
SELECT EXTRACT(MONTH FROM TO_DATE('2022-05-13'));
62-
63-
┌───────────────────────────────────────────┐
64-
│ extract(month from to_date('2022-05-13')) │
65-
│ UInt8 │
66-
├───────────────────────────────────────────┤
67-
5
68-
└───────────────────────────────────────────┘
43+
SELECT NOW(), EXTRACT(DAY FROM NOW()), EXTRACT(DOY FROM NOW()), EXTRACT(EPOCH FROM NOW());
44+
45+
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
46+
│ now() │ EXTRACT(DAY FROM now()) │ EXTRACT(DOY FROM now()) │ EXTRACT(EPOCH FROM now()) │
47+
├────────────────────────────┼─────────────────────────┼─────────────────────────┼───────────────────────────┤
48+
│ 2025-02-08 03:51:51.991167 │ 8 │ 39 │ 1738986711.991167 │
49+
└────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
6950
```

0 commit comments

Comments
 (0)