Skip to content

Commit 257a51d

Browse files
authored
docs: EXTRACT function supports interval (#1663)
* Update extract.md * Update extract.md
1 parent 477c391 commit 257a51d

File tree

1 file changed

+21
-3
lines changed
  • docs/en/sql-reference/20-sql-functions/05-datetime-functions

1 file changed

+21
-3
lines changed

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,20 @@ title: EXTRACT
44

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

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

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

1111
See also: [DATE_PART](date-part.md)
1212

1313
## Syntax
1414

1515
```sql
16-
EXTRACT( YEAR | QUARTER | MONTH | WEEK | DAY | HOUR | MINUTE | SECOND | DOW | DOY | EPOCH FROM <date_or_time_expr> )
16+
-- Extract from a date or timestamp
17+
EXTRACT( YEAR | QUARTER | MONTH | WEEK | DAY | HOUR | MINUTE | SECOND | DOW | DOY | EPOCH FROM <date_or_timestamp> )
18+
19+
-- Extract from an interval
20+
EXTRACT( YEAR | MONTH | WEEK | DAY | HOUR | MINUTE | SECOND | MICROSECOND | EPOCH FROM <interval> )
1721
```
1822

1923
- `DOW`: Day of the Week.
@@ -39,6 +43,8 @@ The return type depends on the field being extracted:
3943

4044
## Examples
4145

46+
This example extracts various fields from the current timestamp:
47+
4248
```sql
4349
SELECT NOW(), EXTRACT(DAY FROM NOW()), EXTRACT(DOY FROM NOW()), EXTRACT(EPOCH FROM NOW());
4450
@@ -47,4 +53,16 @@ SELECT NOW(), EXTRACT(DAY FROM NOW()), EXTRACT(DOY FROM NOW()), EXTRACT(EPOCH FR
4753
├────────────────────────────┼─────────────────────────┼─────────────────────────┼───────────────────────────┤
4854
│ 2025-02-08 03:51:51.991167 │ 8 │ 39 │ 1738986711.991167 │
4955
└────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
56+
```
57+
58+
This example extracts the number of days from an interval:
59+
60+
```sql
61+
SELECT EXTRACT(DAY FROM '1 day 2 hours 3 minutes 4 seconds'::INTERVAL);
62+
63+
┌─────────────────────────────────────────────────────────────────┐
64+
│ EXTRACT(DAY FROM '1 day 2 hours 3 minutes 4 seconds'::INTERVAL) │
65+
├─────────────────────────────────────────────────────────────────┤
66+
│ 1 │
67+
└─────────────────────────────────────────────────────────────────┘
5068
```

0 commit comments

Comments
 (0)