> ## Documentation Index
> Fetch the complete documentation index at: https://docs.e6data.com/llms.txt
> Use this file to discover all available pages before exploring further.

# DATEPART

> Extracts a requested temporal component.

<div className="e6-meta"><span className="e6-eyebrow e6-eyebrow--quiet">Scalar function</span></div>

**Aliases:** [`date_part`](/query/sql/functions/date-time/date_part)

Returns NULL for a NULL date or timestamp. The field must be a non-NULL constant; an unknown field raises an error.

## Syntax

### Datepart form (scalar)

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
datepart(field, value)
```

## Arguments

| Name | Type | Required | Description |
| - | - | - | - |
| field | STRING constant | Yes | Component name. year, month, week, day, hour, minute, second, millisecond, microsecond, nanosecond, isoyear, quarter/qtr, doy, dow, isodow, epoch; E6 aliases years/yr/yrs/y/yy, mons/mon/months, weeks/w/weekiso, days/d, dayofweek, dayofweek\_iso/dow\_iso, dayofyear, yearofweek/yearofweekiso. A field must be applicable to the input type; invalid field/type pairs error. Must be a constant argument. |
| value | DATE, TIME, TIMESTAMP or INTERVAL | Yes | Temporal input. |

## Returns

* Type: INTEGER for ordinary fields; BIGINT for EPOCH
* NULL behavior: Returns NULL for a NULL date or timestamp. The field must be a non-NULL constant; an unknown field raises an error.

## Properties

| Property | Value |
| - | - |
| Deterministic | Yes |
| Exact result | Partial (EPOCH truncates fractional seconds toward zero.) |

## Usage notes

* EPOCH returns BIGINT. Other fields return INTEGER.
* DOW is Sunday=1 through Saturday=7; ISODOW is Monday=1 through Sunday=7.
* Alternate year, month, week, and day names are accepted as listed above. ISO week-year fields use ISO week numbering.
* YEAR and MONTH can handle some out-of-range UTC or timezone-free dates that other fields cannot. Other components remain limited to their supported calendar range.
* EXTRACT uses `EXTRACT(unit FROM value)` syntax. DATE\_PART and DATEPART use a STRING field argument; their reported result types can differ.
* CENTURY and DECADE are not supported. Choose a field that applies to the input type; a field valid for DATE may not apply to TIME, TIMESTAMP, or INTERVAL.

## Examples

### Alias calling form: DATEPART

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT datepart('year',TIMESTAMP '2024-03-15 10:30:45') AS result;
```

| result |
| - |
| 2024 |

### Extract time fields

```sql theme={"theme":{"light":"github-light","dark":"github-dark"}}
SELECT datepart('hour', TIMESTAMP '2024-03-15 10:30:45') AS hour, datepart('minute', TIMESTAMP '2024-03-15 10:30:45') AS minute;
```

| hour | minute |
| - | - |
| 10 | 30 |

## Limitations

* Query tools report BIGINT for DATE\_PART and DATEPART. EPOCH returns BIGINT; other fields return INTEGER.
* Use a STRING literal for the field name. Some STRING representations can return Sunday = 0 for DOW and a floating-point EPOCH value instead of the numbering and type described above.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.