You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/sql-reference/20-sql-functions/05-datetime-functions/extract.md
+26-45Lines changed: 26 additions & 45 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ title: EXTRACT
4
4
5
5
import FunctionDescription from '@site/src/components/FunctionDescription';
6
6
7
-
<FunctionDescriptiondescription="Introduced or updated: v1.2.153"/>
7
+
<FunctionDescriptiondescription="Introduced or updated: v1.2.692"/>
8
8
9
9
Retrieves the designated portion of a date, time, or timestamp.
10
10
@@ -13,57 +13,38 @@ See also: [DATE_PART](date-part.md)
13
13
## Syntax
14
14
15
15
```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> )
17
17
```
18
18
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.
21
22
22
23
## Return Type
23
24
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-0100: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
+
```
25
39
26
40
## Examples
27
41
28
42
```sql
29
-
SELECT NOW();
30
-
31
-
┌────────────────────────────┐
32
-
│ now() │
33
-
├────────────────────────────┤
34
-
│ 2024-05-2203: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());
0 commit comments