---
title: extract
page-cloud: true
latest-operator-version: v26.2.6
latest-console-tag: v3.14.0
latest-connect-version: 4.118.0
latest-redpanda-tag: v26.2.7
docname: sql/sql-functions/timestamp-functions/extract
page-component-name: cloud-data-platform
page-version: master
page-component-version: master
page-component-title: Cloud
page-relative-src-path: sql/sql-functions/timestamp-functions/extract.adoc
page-edit-url: https://github.com/redpanda-data/cloud-docs/edit/main/modules/reference/pages/sql/sql-functions/timestamp-functions/extract.adoc
description: The `extract` function retrieves a specified part (field) from a given date/time or interval value.
page-topic-type: reference
page-git-created-date: "2026-05-26"
page-git-modified-date: "2026-08-03"
page-generated-content: none
---

# extract

> For the complete documentation index, see [llms.txt](https://docs.redpanda.com/llms.txt). Component-specific: [cloud-data-platform-full.txt](https://docs.redpanda.com/cloud-data-platform-full.txt)

<!-- Source: https://docs.redpanda.com/cloud-data-platform/reference/sql/sql-functions/timestamp-functions/extract.md -->

The `extract` function retrieves a specified part (field) from a given date/time or interval value. It is commonly used to obtain components such as year, month, day, and hour from timestamps or dates.

## Syntax

```sql
EXTRACT (field FROM source)
```

## Parameters

-   `field`: String or identifier specifying the part of the date / time to extract.

-   `source`: Date / time value from which to extract the specified field.


This table shows the supported input and corresponding return types for the `extract` function:

| Input Type: `source` | Supported `field` values | Return Type |
| --- | --- | --- |
| `timestamp` | `YEAR`, `MONTH`, `DAY`, `HOUR`, `MINUTE`, `SECOND` | `double precision` |
| `timestamptz` | `YEAR`, `MONTH`, `DAY`, `HOUR`, `MINUTE`, `SECOND` | `double precision` |
| `date` | `YEAR`, `MONTH`, `DAY` | `integer` |

> 📝 **NOTE**
>
> The SECOND field returns a fractional value as `double precision` to include fractional seconds, not an integer type

## Examples

### `extract` with timestamp - year

This example shows how to use the `extract` function to extract a given timestamp’s year:

```sql
SELECT EXTRACT(YEAR FROM TIMESTAMP '2025-12-31 13:30:15.123456');
```

The query returns:

```sql
+----------+
| extract  |
+----------+
| 2025     |
+----------+
```

### `extract` with timestamp - month

This example uses the `extract` function to extract a given timestamp’s month:

```sql
SELECT EXTRACT(MONTH FROM TIMESTAMP '2025-12-31 13:30:15.123456');
```

The query returns the month’s part of the given timestamp:

```sql
+----------+
| extract  |
+----------+
| 12       |
+----------+
```

### `extract` with timestamp - seconds (including fractional seconds)

This example uses the `extract` function to extract a given timestamp’s seconds, including fractional seconds:

```sql
SELECT EXTRACT(SECOND FROM TIMESTAMP '2025-12-31 13:30:15.123456');
```

The query returns the seconds' part of the given timestamp:

```sql
+----------+
| extract  |
+----------+
| 15.123456|
+----------+
```