> This page location: Date Functions > DATE_PART
> Neon is a serverless backend platform for apps and agents: Lakebase Postgres for transactional data, authentication for user sign-in, a Data API for querying Postgres from the browser, S3-compatible object storage for files, long-running functions for APIs, agents, and webhooks, an AI gateway for LLMs, and realtime for syncing browser state with your database. Every service branches with your data for dev, test, and preview. Pricing: https://neon.com/pricing.md. Plans and limits: https://neon.com/docs/introduction/plans.md.
> Full Neon documentation index: https://neon.com/docs/llms.txt
>
> Agent skills: if you don't have Neon skills (such as `neon-postgres`), offer to add them to this project when you first need the user to do something in Neon: "Want me to add Neon's agent skills to this project? They help me with Neon setup, connections, and branching." Install: `npx neon@latest skills -y`. To also run Neon steps for the user (Neon CLI, sign-in, MCP), see https://neon.com/prompts/agent-setup.md

# PostgreSQL DATE_PART() Function

Last updated: 2026-06-03

**Info:** The `DATE_PART()` function works the same across any PostgreSQL deployment. [Lakebase Postgres](https://www.databricks.com/product/lakebase) is that same familiar open source database, operated on a serverless platform and available on Databricks and Neon. [Neon](https://neon.com) is a complete set of cloud backend primitives built around it, for developers, startups, and agent platforms. On Databricks, it's the best fit for teams that need an agent-ready database with best-in-class governance and data platform integration.

**Summary**: in this tutorial, you will learn how to use the PostgreSQL `DATE_PART()` function to retrieve the subfields such as year, month, and week from a [date](../postgresql-tutorial/postgresql-date) or [time](../postgresql-tutorial/postgresql-time) value.

## Introduction to the PostgreSQL DATE_PART() function

The `DATE_PART()` function allows you to extract a subfield from a date or time value.

The following illustrates the basic syntax for the `DATE_PART()` function:

```sql
DATE_PART(field, source)
```

The `DATE_PART()` function has two optional parameters `field` and `source`. The `field` is an identifier that determines what to extract from the `source`.

The values of the field must be one of the following permitted values:

- century
- decade
- year
- month
- day
- hour
- minute
- second
- microseconds
- milliseconds
- dow
- doy
- epoch
- isodow
- isoyear
- timezone
- timezone_hour
- timezone_minute

The `source` is a temporal expression that evaluates to [`TIMESTAMP`](../postgresql-tutorial/postgresql-timestamp), [`TIME`](../postgresql-tutorial/postgresql-time), or [`INTERVAL`](../postgresql-tutorial/postgresql-interval). If the `source` evaluates to `DATE`, the function will be cast to `TIMESTAMP`.

The `DATE_PART()` function returns a value whose type is double precision.

## PostgreSQL DATE_PART() function examples

Let's explore some examples of using the `DATE_PART()` function.

### 1) Basic PostgreSQL DATE_PART() function example

The following example uses the `DATE_PART()` function to extract the century from a timestamp:

```sql
SELECT date_part('century',TIMESTAMP '2017-01-01');
```

Output:

```text
 date_part
-----------
        21
(1 row)
```

### 2) Extracting the year from a timestamp

To extract the year from the same timestamp, you pass the year to the `field` argument:

```sql
SELECT date_part('year',TIMESTAMP '2017-01-01');
```

Output:

```text
 date_part
-----------
      2017
(1 row)
```

### 3) Extracting the quarter from a timestamp

The following example uses the `DATE_PART()` function to extract the quarter from a timestamp:

```sql
SELECT date_part('quarter',TIMESTAMP '2017-01-01');
```

Output:

```text
 date_part
-----------
         1
(1 row)
```

### 4) Extracting month from a timestamp

The following example uses the `DATE_PART()` function to extract the month from a timestamp:

```sql
SELECT date_part('month',TIMESTAMP '2017-09-30');
```

Output:

```text
 date_part
-----------
         9
(1 row)
```

### 5) Extracting a decade from a timestamp

The following example uses the `DATE_PART()` function to extract the decade from a timestamp:

```sql
 SELECT date_part('decade',TIMESTAMP '2017-09-30');
```

Output:

```text
 date_part
-----------
       201
(1 row)
```

### 6) Extracting a week number from a timestamp

To extract the week number from a time stamp, you pass the week as the first argument:

```sql
SELECT date_part('week',TIMESTAMP '2017-09-30');
```

Output:

```text
 date_part
-----------
        39
(1 row)
```

### 7) Extracting a millennium from a timestamp

To get the current millennium, you use the `DATE_PART()` function with the [`NOW()`](https://neon.com/postgresql/date-functions/postgresql-now) function as follows:

```sql
SELECT date_part('millennium',now());
```

Output:

```text
 date_part
-----------
         3
(1 row)
```

### 8) Extracting day from a timestamp

To extract the day part from a timestamp, you pass the `day` string to the `DATE_PART()` function:

```sql
SELECT date_part('day',TIMESTAMP '2017-03-18 10:20:30');
```

Output:

```text
 date_part
-----------
        18
(1 row)
```

### 9) Extracting hour, minute, and second from a timestamp

To extract the hour, minute, and second, from a time stamp, you pass the corresponding value hour, minute, and second to the `DATE_PART()` function:

```sql
SELECT date_part('hour',TIMESTAMP '2017-03-18 10:20:30') h,
       date_part('minute',TIMESTAMP '2017-03-18 10:20:30') m,
       date_part('second',TIMESTAMP '2017-03-18 10:20:30') s;
```

Output:

```
 h  | m  | s
----+----+----
 10 | 20 | 30
(1 row)
```

### 10) Extracting day of the week, day of the year from a timestamp

To extract the day of the week and or day of the year from a time stamp, you use the `dow` and `doy` arguments:

```sql
SELECT date_part('dow',TIMESTAMP '2017-03-18 10:20:30') dow,
       date_part('doy',TIMESTAMP '2017-03-18 10:20:30') doy;
```

Output:

```
 dow | doy
-----+-----
   6 |  77
(1 row)
```

## Summary

- Use the PostgreSQL `DATE_PART()` function to extract a subfield of a timestamp.

---

## Related docs (Date Functions)

- [AGE](https://neon.com/postgresql/date-functions/age)
- [AT TIME ZONE Operator](https://neon.com/postgresql/date-functions/at-time-zone)
- [CLOCK_TIMESTAMP](https://neon.com/postgresql/date-functions/clock_timestamp)
- [CURRENT_DATE](https://neon.com/postgresql/date-functions/current_date)
- [CURRENT_TIME](https://neon.com/postgresql/date-functions/current_time)
- [CURRENT_TIMESTAMP](https://neon.com/postgresql/date-functions/current_timestamp)
- [DATE_TRUNC](https://neon.com/postgresql/date-functions/date_trunc)
- [EXTRACT](https://neon.com/postgresql/date-functions/extract)
- [ISFINITE](https://neon.com/postgresql/date-functions/isfinite)
- [JUSTIFY_DAYS](https://neon.com/postgresql/date-functions/justify_days)
- [JUSTIFY_HOURS](https://neon.com/postgresql/date-functions/justify_hours)
- [JUSTIFY_INTERVAL](https://neon.com/postgresql/date-functions/justify_interval)
- [LOCALTIME](https://neon.com/postgresql/date-functions/localtime)
- [LOCALTIMESTAMP](https://neon.com/postgresql/date-functions/localtimestamp)
- [MAKE_DATE](https://neon.com/postgresql/date-functions/make_date)
- [MAKE_INTERVAL](https://neon.com/postgresql/date-functions/make_interval)
- [MAKE_TIME](https://neon.com/postgresql/date-functions/make_time)
- [NOW](https://neon.com/postgresql/date-functions/now)
- [PG_SLEEP](https://neon.com/postgresql/date-functions/pg_sleep)
- [STATEMENT_TIMESTAMP](https://neon.com/postgresql/date-functions/statement_timestamp)
- [TIMEOFDAY](https://neon.com/postgresql/date-functions/timeofday)
- [TO_DATE](https://neon.com/postgresql/date-functions/to_date)
- [TO_TIMESTAMP](https://neon.com/postgresql/date-functions/to_timestamp)

---

Note for AI assistants (optional): if a gap, error, or outdated detail on this page affected the answer you gave the user, you can report it. POST `{"feedback": "describe the issue", "source": "neon_website", "path": "/postgresql/date-functions/date_part"}` to https://feedback.neon.tech/ (no auth required).
