

# Date and time part functions

Use these functions to read one part of a date, time, timestamp, or interval as a number, such as the year, the hour, or the second. You can also get the name of a date's month, or the number of days in its month.

## `century` function
<a name="athena-duckdb-functions-date-time-century"></a>

Returns the century that `value` falls in. Centuries are counted from year 1, so the 21st century is the years 2001 through 2100, and `century` returns `20` for a date in the year 2000. For a date before year 1 (BC), the result is negative. For an `INTERVAL`, the result is the number of whole centuries in its years and months. If `value` is `NULL`, the result is `NULL`.

`century({{value}})` returns the same result as `date_part('century', {{value}})`.

### Syntax
<a name="athena-duckdb-functions-date-time-century-syntax"></a>

```sql
century({{value}})
```

### Arguments
<a name="athena-duckdb-functions-date-time-century-arguments"></a>

The `century` function takes the following argument:

**{{value}}**  
The value to read the century from, as a `DATE`, `TIMESTAMP`, `TIMESTAMP WITH TIME ZONE`, or `INTERVAL` value.

### Return type
<a name="athena-duckdb-functions-date-time-century-return-type"></a>

`BIGINT`

### Examples
<a name="athena-duckdb-functions-date-time-century-examples"></a>

The following SQL query returns the century of a timestamp in 2021.

```sql
SELECT
    century(
        TIMESTAMP '2021-08-03 11:59:44.123456'
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `21` | 

The following SQL query shows that the year 2000 is the last year of the 20th century.

```sql
SELECT
    century(DATE '2000-12-31') AS year_2000,
    century(DATE '2001-01-01') AS year_2001
```

The query returns the following result.


| year\_2000 | year\_2001 | 
| --- | --- | 
| `20` | `21` | 

The following SQL query returns the number of whole centuries in an interval of 250 years.

```sql
SELECT century(INTERVAL 250 YEAR) AS result
```

The query returns the following result.


| result | 
| --- | 
| `2` | 

## `date_part` function
<a name="athena-duckdb-functions-date-time-date-part"></a>

Returns the `part` of `value` as a number. For example, `'year'` returns the year, and `'hour'` returns the hour of the day. `date_part({{part}}, {{value}})` returns the same result as `extract({{part}} FROM {{value}})`. If `value` is `NULL`, the result is `NULL`.

With a list of part names, `date_part` returns all of them at once, as a `STRUCT` that has one field for each part, in the order of the list.

For an `INTERVAL`, each part is read from the interval as it is stored, so `date_part('hour', INTERVAL '90 minutes')` returns `1` and `date_part('minute', INTERVAL '90 minutes')` returns `30`. The `datepart` function takes the same arguments and returns the same results.

### Syntax
<a name="athena-duckdb-functions-date-time-date-part-syntax"></a>

```sql
date_part({{part}}, {{value}})
date_part({{part_list}}, {{value}})
```

### Arguments
<a name="athena-duckdb-functions-date-time-date-part-arguments"></a>

The `date_part` function takes the following arguments:

**{{part}}**  
The name of the part to read, as a `VARCHAR` value, such as `'year'`, `'month'`, `'day'`, `'hour'`, `'dow'` (the day of the week, with Sunday as 0), or `'epoch'`. Case is ignored, and plural and short forms such as `'years'` and `'y'` also work. For the full list of part names, see [Date and time functions and operators in DuckDB](duckdb-functions-date-time.md).

**{{part\_list}}**  
The parts to read, as a list of `VARCHAR` part names, such as `['year', 'month', 'day']`.

**{{value}}**  
The value to read the part from, as a `DATE`, `TIME`, `TIME WITH TIME ZONE`, `TIMESTAMP`, `TIMESTAMP WITH TIME ZONE`, or `INTERVAL` value. Nanosecond values such as `TIMESTAMP_NS` are accepted too.

### Return type
<a name="athena-duckdb-functions-date-time-date-part-return-type"></a>

`BIGINT` for most parts, and `DOUBLE` for `'epoch'` and `'julian'`. With `part_list`, a `STRUCT` whose fields have those types.

### Examples
<a name="athena-duckdb-functions-date-time-date-part-examples"></a>

The following SQL query returns the minute of a timestamp.

```sql
SELECT
    date_part(
        'minute', TIMESTAMP '1992-09-20 20:38:40'
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `38` | 

The following SQL query returns the year, month, and day of a date in one `STRUCT`.

```sql
SELECT
    date_part(
        ['year', 'month', 'day'], DATE '2026-11-18'
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `{'year': 2026, 'month': 11, 'day': 18}` | 

The following SQL query shows that `'millisecond'` and `'microsecond'` include the seconds.

```sql
SELECT
    date_part(
        'second', TIMESTAMP '2026-11-18 10:11:12.345678'
    ) AS second_part,
    date_part(
        'millisecond',
        TIMESTAMP '2026-11-18 10:11:12.345678'
    ) AS millisecond_part,
    date_part(
        'microsecond',
        TIMESTAMP '2026-11-18 10:11:12.345678'
    ) AS microsecond_part
```

The query returns the following result.


| second\_part | millisecond\_part | microsecond\_part | 
| --- | --- | --- | 
| `12` | `12345` | `12345678` | 

The following SQL query reads the hour of a `TIMESTAMP WITH TIME ZONE` value. 10:00 at UTC\+5 is 05:00 in UTC, so the result is `5`.

```sql
SELECT
    date_part(
        'hour', TIMESTAMPTZ '2026-11-18 10:00:00+05'
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `5` | 

### Considerations
<a name="athena-duckdb-functions-date-time-date-part-considerations"></a>

`'second'` returns whole seconds. `'millisecond'` and `'microsecond'` include the seconds, so for a time of 10:11:12.345678 they return `12345` and `12345678`. To get only the milliseconds within the second, use `date_part('millisecond', {{value}}) % 1000`.

A `TIMESTAMP WITH TIME ZONE` value is read in UTC, not in the time zone that it was written with. For the same reason, `'timezone'` returns `0` for a `TIMESTAMP WITH TIME ZONE` value. A `TIME WITH TIME ZONE` value keeps its offset, so `'timezone'` returns that offset in seconds, such as `-25200` for `TIMETZ '18:18:16-07:00'`.

## `day` function
<a name="athena-duckdb-functions-date-time-day"></a>

Returns the day of the month of `value`, from 1 to 31. For an `INTERVAL`, `day` returns only the days part. It does not convert months or hours to days, so `day(INTERVAL 36 HOUR)` returns `0`. If `value` is `NULL`, the result is `NULL`.

`day({{value}})` returns the same result as `date_part('day', {{value}})`.

`dayofmonth` is an alias of `day`.

### Syntax
<a name="athena-duckdb-functions-date-time-day-syntax"></a>

```sql
day({{value}})
```

### Arguments
<a name="athena-duckdb-functions-date-time-day-arguments"></a>

The `day` function takes the following argument:

**{{value}}**  
The value to read the day from, as a `DATE`, `TIMESTAMP`, `TIMESTAMP WITH TIME ZONE`, or `INTERVAL` value.

### Return type
<a name="athena-duckdb-functions-date-time-day-return-type"></a>

`BIGINT`

### Examples
<a name="athena-duckdb-functions-date-time-day-examples"></a>

The following SQL query returns the day of the month of a timestamp.

```sql
SELECT
    day(
        TIMESTAMP '2021-08-03 11:59:44.123456'
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `3` | 

The following SQL query returns the days part of three intervals. The months and the hours are not converted to days.

```sql
SELECT
    day(INTERVAL '40 days') AS days_40,
    day(INTERVAL '1 month 5 days') AS month_and_5_days,
    day(INTERVAL 36 HOUR) AS hours_36
```

The query returns the following result.


| days\_40 | month\_and\_5\_days | hours\_36 | 
| --- | --- | --- | 
| `40` | `5` | `0` | 

The following SQL query reads the day of a `TIMESTAMP WITH TIME ZONE` value. At UTC-5, 22:00 on November 18 is 03:00 on November 19 in UTC, so the result is `19`.

```sql
SELECT
    day(TIMESTAMPTZ '2026-11-18 22:00:00-05') AS result
```

The query returns the following result.


| result | 
| --- | 
| `19` | 

### Considerations
<a name="athena-duckdb-functions-date-time-day-considerations"></a>

A `TIMESTAMP WITH TIME ZONE` value is read in UTC, so the day can differ from the day in the time zone that the value was written with.

### Differences from Athena engine version 3
<a name="athena-duckdb-functions-date-time-day-differences-from-engine-version-3"></a>

In Athena engine version 3, a `TIMESTAMP WITH TIME ZONE` value keeps its time zone, and `day` returns the day in that time zone. In DuckDB, the value is read in UTC. For example, for 22:00 on November 18 at UTC-5, Athena engine version 3 returns `18`, and DuckDB returns `19`.

## `dayofyear` function
<a name="athena-duckdb-functions-date-time-dayofyear"></a>

Returns the day of the year of `ts`, where January 1 is `1`. December 31 is `365`, or `366` in a leap year. If `ts` is `NULL`, the result is `NULL`.

### Syntax
<a name="athena-duckdb-functions-date-time-dayofyear-syntax"></a>

```sql
dayofyear({{ts}})
```

### Arguments
<a name="athena-duckdb-functions-date-time-dayofyear-arguments"></a>

The `dayofyear` function takes the following argument:

**{{ts}}**  
The value to read the day of the year from, as a `DATE`, `TIMESTAMP`, or `TIMESTAMP WITH TIME ZONE` value.

### Return type
<a name="athena-duckdb-functions-date-time-dayofyear-return-type"></a>

`BIGINT`

### Examples
<a name="athena-duckdb-functions-date-time-dayofyear-examples"></a>

The following SQL query returns the day of the year of a timestamp.

```sql
SELECT
    dayofyear(
        TIMESTAMP '2021-08-03 11:59:44.123456'
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `215` | 

The following SQL query returns the day of the year of December 31 in a leap year and in a common year.

```sql
SELECT
    dayofyear(DATE '2024-12-31') AS leap_year,
    dayofyear(DATE '2023-12-31') AS common_year
```

The query returns the following result.


| leap\_year | common\_year | 
| --- | --- | 
| `366` | `365` | 

### Considerations
<a name="athena-duckdb-functions-date-time-dayofyear-considerations"></a>

For a `TIMESTAMP WITH TIME ZONE` value, the day is taken in the session time zone, which is UTC.

`dayofyear` does not work on `INTERVAL` values. A call such as `dayofyear(INTERVAL '3 days')` fails.

### Differences from Athena engine version 3
<a name="athena-duckdb-functions-date-time-dayofyear-differences-from-engine-version-3"></a>

Athena engine version 3 names this function `day_of_year`. DuckDB does not have `day_of_year`, so use `dayofyear`.

## `days_in_month` function
<a name="athena-duckdb-functions-date-time-days-in-month"></a>

Returns the number of days in the month that contains `date`, a number from `28` to `31`. February has `29` days in a leap year. If `date` is `NULL`, the result is `NULL`.

`days_in_month` is a macro that returns `day(last_day({{date}}))`. To get the last day of the month as a date, use the [`last_day` function](duckdb-functions-date-time-truncation.md#athena-duckdb-functions-date-time-last-day).

### Syntax
<a name="athena-duckdb-functions-date-time-days-in-month-syntax"></a>

```sql
days_in_month({{date}})
```

### Arguments
<a name="athena-duckdb-functions-date-time-days-in-month-arguments"></a>

The `days_in_month` function takes the following argument:

**{{date}}**  
A value in the month whose days to count, as a `DATE`, `TIMESTAMP`, or `TIMESTAMP WITH TIME ZONE` value.

### Return type
<a name="athena-duckdb-functions-date-time-days-in-month-return-type"></a>

`BIGINT`

### Examples
<a name="athena-duckdb-functions-date-time-days-in-month-examples"></a>

The following SQL query returns the number of days in February 2024, a leap year.

```sql
SELECT days_in_month(DATE '2024-02-10') AS result
```

The query returns the following result.


| result | 
| --- | 
| `29` | 

The following SQL query returns the number of days in February 2023, a common year.

```sql
SELECT days_in_month(DATE '2023-02-10') AS result
```

The query returns the following result.


| result | 
| --- | 
| `28` | 

The following SQL query casts the string `'2023-04-10'` to `DATE` first, and returns the number of days in April 2023.

```sql
SELECT
    days_in_month(CAST('2023-04-10' AS DATE)) AS result
```

The query returns the following result.


| result | 
| --- | 
| `30` | 

### Considerations
<a name="athena-duckdb-functions-date-time-days-in-month-considerations"></a>

A string literal is not converted to a date for you. A call such as `days_in_month('2023-04-10')` fails, so cast the string first, as in `days_in_month(CAST('2023-04-10' AS DATE))`.

## `decade` function
<a name="athena-duckdb-functions-date-time-decade"></a>

Returns the year of `ts` divided by 10, with the remainder dropped. For example, every date from 2020 through 2029 returns `202`. For an `INTERVAL` value, returns the number of whole years in the interval divided by 10. If `ts` is `NULL`, the result is `NULL`.

To get the century or the millennium, use the [`century` function](#athena-duckdb-functions-date-time-century) or the [`millennium` function](#athena-duckdb-functions-date-time-millennium).

### Syntax
<a name="athena-duckdb-functions-date-time-decade-syntax"></a>

```sql
decade({{ts}})
```

### Arguments
<a name="athena-duckdb-functions-date-time-decade-arguments"></a>

The `decade` function takes the following argument:

**{{ts}}**  
The value to read the decade from, as a `DATE`, `TIMESTAMP`, `TIMESTAMP WITH TIME ZONE`, or `INTERVAL` value.

### Return type
<a name="athena-duckdb-functions-date-time-decade-return-type"></a>

`BIGINT`

### Examples
<a name="athena-duckdb-functions-date-time-decade-examples"></a>

The following SQL query returns the decade of a timestamp in 2021.

```sql
SELECT
    decade(
        TIMESTAMP '2021-08-03 11:59:44.123456'
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `202` | 

The following SQL query shows that a decade runs from a year that ends in 0 through a year that ends in 9.

```sql
SELECT
    decade(DATE '1999-12-31') AS last_day_of_1990s,
    decade(DATE '2000-01-01') AS first_day_of_2000s
```

The query returns the following result.


| last\_day\_of\_1990s | first\_day\_of\_2000s | 
| --- | --- | 
| `199` | `200` | 

The following SQL query returns the number of whole decades in an interval of 25 years.

```sql
SELECT decade(INTERVAL '25 years') AS result
```

The query returns the following result.


| result | 
| --- | 
| `2` | 

## `era` function
<a name="athena-duckdb-functions-date-time-era"></a>

Returns `1` when `ts` is in year 1 or later (AD), and `0` when it is before year 1 (BC). If `ts` is `NULL`, the result is `NULL`.

To write a date before year 1 as a literal, add `(BC)` after the date, as in `DATE '0044-03-15 (BC)'`.

### Syntax
<a name="athena-duckdb-functions-date-time-era-syntax"></a>

```sql
era({{ts}})
```

### Arguments
<a name="athena-duckdb-functions-date-time-era-arguments"></a>

The `era` function takes the following argument:

**{{ts}}**  
The value to read the era from, as a `DATE`, `TIMESTAMP`, or `TIMESTAMP WITH TIME ZONE` value.

### Return type
<a name="athena-duckdb-functions-date-time-era-return-type"></a>

`BIGINT`

### Examples
<a name="athena-duckdb-functions-date-time-era-examples"></a>

The following SQL query returns the era of a timestamp in 2021.

```sql
SELECT
    era(
        TIMESTAMP '2021-08-03 11:59:44.123456'
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `1` | 

The following SQL query compares a date in 44 BC with the same day and month in AD 44.

```sql
SELECT
    era(DATE '0044-03-15 (BC)') AS bc_date,
    era(DATE '0044-03-15') AS ad_date
```

The query returns the following result.


| bc\_date | ad\_date | 
| --- | --- | 
| `0` | `1` | 

### Considerations
<a name="athena-duckdb-functions-date-time-era-considerations"></a>

`era` does not work on `INTERVAL` values. A call such as `era(INTERVAL '5 years')` fails.

## `hour` function
<a name="athena-duckdb-functions-date-time-hour"></a>

Returns the hour of `ts`, a number from `0` to `23`. For a `DATE` value, the result is `0`. If `ts` is `NULL`, the result is `NULL`.

For an `INTERVAL` value, returns the hours part of the interval. An interval stores days separately from hours, so the result can be `24` or more: `hour(INTERVAL '30 hours')` returns `30`, but `hour(INTERVAL '1 day 3 hours')` returns `3`.

### Syntax
<a name="athena-duckdb-functions-date-time-hour-syntax"></a>

```sql
hour({{ts}})
```

### Arguments
<a name="athena-duckdb-functions-date-time-hour-arguments"></a>

The `hour` function takes the following argument:

**{{ts}}**  
The value to read the hour from, as a `DATE`, `TIME`, `TIME_NS`, `TIME WITH TIME ZONE`, `TIMESTAMP`, `TIMESTAMP_NS`, `TIMESTAMP WITH TIME ZONE`, or `INTERVAL` value.

### Return type
<a name="athena-duckdb-functions-date-time-hour-return-type"></a>

`BIGINT`

### Examples
<a name="athena-duckdb-functions-date-time-hour-examples"></a>

The following SQL query returns the hour of a timestamp.

```sql
SELECT
    hour(
        TIMESTAMP '2021-08-03 11:59:44.123456'
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `11` | 

The following SQL query passes 11:15 PM at UTC offset \+05. In UTC, that time is 6:15 PM, so the function returns `18`.

```sql
SELECT
    hour(TIMESTAMPTZ '2021-08-03 23:15:00+05') AS result
```

The query returns the following result.


| result | 
| --- | 
| `18` | 

The following SQL query returns the hours part of two intervals. The second interval stores its day separately from its hours, so the function returns only its `3` hours.

```sql
SELECT
    hour(INTERVAL '30 hours') AS thirty_hours,
    hour(
        INTERVAL '1 day 3 hours'
    ) AS one_day_three_hours
```

The query returns the following result.


| thirty\_hours | one\_day\_three\_hours | 
| --- | --- | 
| `30` | `3` | 

### Considerations
<a name="athena-duckdb-functions-date-time-hour-considerations"></a>

For a `TIMESTAMP WITH TIME ZONE` value, the hour is taken in the session time zone, which is UTC, not at the offset that the value was written with.

For a `TIME WITH TIME ZONE` value, the hour is the one written in the value, and the offset is not applied.

## `microsecond` function
<a name="athena-duckdb-functions-date-time-microsecond"></a>

Returns the seconds part of `ts`, including its fraction, as a number of microseconds. The result is from `0` to `59999999`, so `11:59:44.123456` gives `44123456`, not `123456`. For a `DATE`, the result is `0`. For an `INTERVAL`, the result is the seconds part of its time after whole minutes are removed, so `INTERVAL '90 seconds'` gives `30000000`.

`microsecond({{ts}})` returns the same value as `date_part('microseconds', {{ts}})`. If `ts` is `NULL`, the result is `NULL`.

### Syntax
<a name="athena-duckdb-functions-date-time-microsecond-syntax"></a>

```sql
microsecond({{ts}})
```

### Arguments
<a name="athena-duckdb-functions-date-time-microsecond-arguments"></a>

The `microsecond` function takes the following argument:

**{{ts}}**  
The value to read the seconds and fractional seconds from, as a `DATE`, `TIME`, `TIME WITH TIME ZONE`, `TIMESTAMP`, `TIMESTAMP WITH TIME ZONE`, `TIMESTAMP_NS`, or `INTERVAL` value.

### Return type
<a name="athena-duckdb-functions-date-time-microsecond-return-type"></a>

`BIGINT`

### Examples
<a name="athena-duckdb-functions-date-time-microsecond-examples"></a>

The following SQL query returns the seconds of a timestamp in microseconds.

```sql
SELECT
    microsecond(
        TIMESTAMP '2021-08-03 11:59:44.123456'
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `44123456` | 

The following SQL query compares the full result with the fractional part only.

```sql
SELECT
    microsecond(
        TIMESTAMP '2021-08-03 11:59:44.123456'
    ) AS total_us,
    microsecond(
        TIMESTAMP '2021-08-03 11:59:44.123456'
    ) % 1000000 AS fraction_us
```

The query returns the following result.


| total\_us | fraction\_us | 
| --- | --- | 
| `44123456` | `123456` | 

### Considerations
<a name="athena-duckdb-functions-date-time-microsecond-considerations"></a>

To get only the fractional part of the second, from `0` to `999999`, use `microsecond({{ts}}) % 1000000`.

## `millennium` function
<a name="athena-duckdb-functions-date-time-millennium"></a>

Returns the millennium that `ts` falls in. Millennia start with year 1, so years 1 to 1000 are millennium `1` and years 2001 to 3000 are millennium `3`. The year 2000 is in millennium `2`. For an `INTERVAL`, the result is the number of whole millennia in its years part.

`millennium({{ts}})` returns the same value as `date_part('millennium', {{ts}})`. If `ts` is `NULL`, the result is `NULL`.

### Syntax
<a name="athena-duckdb-functions-date-time-millennium-syntax"></a>

```sql
millennium({{ts}})
```

### Arguments
<a name="athena-duckdb-functions-date-time-millennium-arguments"></a>

The `millennium` function takes the following argument:

**{{ts}}**  
The value to read the millennium from, as a `DATE`, `TIMESTAMP`, `TIMESTAMP WITH TIME ZONE`, or `INTERVAL` value.

### Return type
<a name="athena-duckdb-functions-date-time-millennium-return-type"></a>

`BIGINT`

### Examples
<a name="athena-duckdb-functions-date-time-millennium-examples"></a>

The following SQL query returns the millennium of a timestamp.

```sql
SELECT
    millennium(
        TIMESTAMP '2021-08-03 11:59:44.123456'
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `3` | 

The following SQL query shows that the last day of 2000 is still in the second millennium, and the third millennium starts on January 1, 2001.

```sql
SELECT
    millennium(DATE '2000-12-31') AS last_day_2000,
    millennium(DATE '2001-01-01') AS first_day_2001
```

The query returns the following result.


| last\_day\_2000 | first\_day\_2001 | 
| --- | --- | 
| `2` | `3` | 

The following SQL query returns the number of whole millennia in an interval of 2,500 years.

```sql
SELECT millennium(INTERVAL '2500 years') AS result
```

The query returns the following result.


| result | 
| --- | 
| `2` | 

## `millisecond` function
<a name="athena-duckdb-functions-date-time-millisecond"></a>

Returns the seconds part of `ts`, including its fraction, as a whole number of milliseconds. The result is from `0` to `59999`, so `11:59:44.123456` gives `44123`, not `123`. Digits finer than a millisecond are dropped. For a `DATE`, the result is `0`.

`millisecond({{ts}})` returns the same value as `date_part('millisecond', {{ts}})`. If `ts` is `NULL`, the result is `NULL`.

### Syntax
<a name="athena-duckdb-functions-date-time-millisecond-syntax"></a>

```sql
millisecond({{ts}})
```

### Arguments
<a name="athena-duckdb-functions-date-time-millisecond-arguments"></a>

The `millisecond` function takes the following argument:

**{{ts}}**  
The value to read the seconds and fractional seconds from, as a `DATE`, `TIME`, `TIME WITH TIME ZONE`, `TIMESTAMP`, `TIMESTAMP WITH TIME ZONE`, `TIMESTAMP_NS`, or `INTERVAL` value.

### Return type
<a name="athena-duckdb-functions-date-time-millisecond-return-type"></a>

`BIGINT`

### Examples
<a name="athena-duckdb-functions-date-time-millisecond-examples"></a>

The following SQL query returns the seconds of a timestamp in milliseconds.

```sql
SELECT
    millisecond(
        TIMESTAMP '2021-08-03 11:59:44.123456'
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `44123` | 

The following SQL query compares the full result with the milliseconds within the second only.

```sql
SELECT
    millisecond(
        TIMESTAMP '2021-08-03 11:59:44.123456'
    ) AS total_ms,
    millisecond(
        TIMESTAMP '2021-08-03 11:59:44.123456'
    ) % 1000 AS within_second_ms
```

The query returns the following result.


| total\_ms | within\_second\_ms | 
| --- | --- | 
| `44123` | `123` | 

### Considerations
<a name="athena-duckdb-functions-date-time-millisecond-considerations"></a>

To get only the milliseconds within the second, from `0` to `999`, use `millisecond({{ts}}) % 1000`.

### Differences from Athena engine version 3
<a name="athena-duckdb-functions-date-time-millisecond-differences-from-engine-version-3"></a>

In Athena engine version 3, `millisecond` returns only the milliseconds within the second, from `0` to `999`. In DuckDB, the result includes the seconds, from `0` to `59999`. To get the Athena engine version 3 result, use `millisecond({{ts}}) % 1000`.

## `minute` function
<a name="athena-duckdb-functions-date-time-minute"></a>

Returns the minute of `ts`, from `0` to `59`. For a `DATE`, the result is `0`. For an `INTERVAL`, the result is the minutes part of its time, not its total length in minutes, so `INTERVAL '150 minutes'` gives `30`.

A `TIMESTAMP WITH TIME ZONE` value is read in the session time zone, which is UTC. `minute({{ts}})` returns the same value as `date_part('minute', {{ts}})`. If `ts` is `NULL`, the result is `NULL`.

### Syntax
<a name="athena-duckdb-functions-date-time-minute-syntax"></a>

```sql
minute({{ts}})
```

### Arguments
<a name="athena-duckdb-functions-date-time-minute-arguments"></a>

The `minute` function takes the following argument:

**{{ts}}**  
The value to read the minute from, as a `DATE`, `TIME`, `TIME WITH TIME ZONE`, `TIMESTAMP`, `TIMESTAMP WITH TIME ZONE`, `TIMESTAMP_NS`, or `INTERVAL` value.

### Return type
<a name="athena-duckdb-functions-date-time-minute-return-type"></a>

`BIGINT`

### Examples
<a name="athena-duckdb-functions-date-time-minute-examples"></a>

The following SQL query returns the minute of a timestamp.

```sql
SELECT
    minute(
        TIMESTAMP '2021-08-03 11:59:44.123456'
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `59` | 

The following SQL query returns the minutes part of an interval of 150 minutes, which is 2 hours and 30 minutes.

```sql
SELECT minute(INTERVAL '150 minutes') AS result
```

The query returns the following result.


| result | 
| --- | 
| `30` | 

The following SQL query reads the minute of a timestamp with time zone in UTC, and then in the time zone of the original value.

```sql
SELECT
    minute(
        TIMESTAMPTZ '2021-08-03 11:59:44+05:30'
    ) AS utc_minute,
    minute(
        TIMESTAMPTZ '2021-08-03 11:59:44+05:30' AT TIME ZONE 'Asia/Kolkata'
    ) AS local_minute
```

The query returns the following result.


| utc\_minute | local\_minute | 
| --- | --- | 
| `29` | `59` | 

### Considerations
<a name="athena-duckdb-functions-date-time-minute-considerations"></a>

Some time zones have an offset that is not a whole number of hours, such as India Standard Time (UTC\+5:30). For a `TIMESTAMP WITH TIME ZONE` value in such a time zone, the minute in UTC differs from the local minute. To read the local minute, convert the value first, as in `minute({{ts}} AT TIME ZONE 'Asia/Kolkata')`.

### Differences from Athena engine version 3
<a name="athena-duckdb-functions-date-time-minute-differences-from-engine-version-3"></a>

In Athena engine version 3, a `TIMESTAMP WITH TIME ZONE` value keeps its own time zone, and `minute` returns the minute in that zone. In DuckDB, the value is read in the session time zone, UTC. For 11:59:44 at UTC\+5:30, Athena engine version 3 returns `59` and DuckDB returns `29`. To get the Athena engine version 3 result, convert the value with `AT TIME ZONE` before you call `minute`.

## `month` function
<a name="athena-duckdb-functions-date-time-month"></a>

Returns the month of `ts`, from `1` for January to `12` for December. For an `INTERVAL`, the result is the months that are left after whole years. This value is from `0` to `11`, or from `-11` to `0` for a negative interval. For example, `INTERVAL '-14 months'` gives `-2`. Days in an interval are not converted to months, so `INTERVAL '45 days'` gives `0`.

A `TIMESTAMP WITH TIME ZONE` value is read in the session time zone, which is UTC. `month({{ts}})` returns the same value as `date_part('month', {{ts}})` and `EXTRACT(MONTH FROM {{ts}})`. If `ts` is `NULL`, the result is `NULL`.

### Syntax
<a name="athena-duckdb-functions-date-time-month-syntax"></a>

```sql
month({{ts}})
```

### Arguments
<a name="athena-duckdb-functions-date-time-month-arguments"></a>

The `month` function takes the following argument:

**{{ts}}**  
The value to read the month from, as a `DATE`, `TIMESTAMP`, `TIMESTAMP WITH TIME ZONE`, or `INTERVAL` value.

### Return type
<a name="athena-duckdb-functions-date-time-month-return-type"></a>

`BIGINT`

### Examples
<a name="athena-duckdb-functions-date-time-month-examples"></a>

The following SQL query returns the month of a timestamp.

```sql
SELECT
    month(
        TIMESTAMP '2021-08-03 11:59:44.123456'
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `8` | 

The following SQL query returns the months part of an interval of 14 months, and of an interval of 45 days, whose days are not counted as months.

```sql
SELECT
    month(INTERVAL '14 months') AS from_months,
    month(INTERVAL '45 days') AS from_days
```

The query returns the following result.


| from\_months | from\_days | 
| --- | --- | 
| `2` | `0` | 

The following SQL query reads the month of a timestamp with time zone in UTC, and then in a time zone that is 5 hours behind UTC on that date.

```sql
SELECT
    month(
        TIMESTAMPTZ '2021-08-31 23:30:00-05'
    ) AS utc_month,
    month(
        TIMESTAMPTZ '2021-08-31 23:30:00-05' AT TIME ZONE 'America/Chicago'
    ) AS local_month
```

The query returns the following result.


| utc\_month | local\_month | 
| --- | --- | 
| `9` | `8` | 

### Considerations
<a name="athena-duckdb-functions-date-time-month-considerations"></a>

`month` does not accept a string. A call such as `month('2021-08-03')` fails, so cast the string first, as in `month(CAST('2021-08-03' AS DATE))`.

For a `TIMESTAMP WITH TIME ZONE` value near the end of a month, the month in UTC can differ from the local month. To read the local month, convert the value first, as in `month({{ts}} AT TIME ZONE 'America/Chicago')`.

### Differences from Athena engine version 3
<a name="athena-duckdb-functions-date-time-month-differences-from-engine-version-3"></a>

In Athena engine version 3, a `TIMESTAMP WITH TIME ZONE` value keeps its own time zone, and `month` returns the month in that zone. In DuckDB, the value is read in the session time zone, UTC. For 2021-08-31 23:30 at UTC-5, Athena engine version 3 returns `8` and DuckDB returns `9`. To get the Athena engine version 3 result, convert the value with `AT TIME ZONE` before you call `month`.

## `monthname` function
<a name="athena-duckdb-functions-date-time-monthname"></a>

Returns the month of `ts` spelled out in full as an English word, such as `September`. For a three-letter abbreviation, such as `Sep`, use `strftime({{ts}}, '%b')`.

A `TIMESTAMP WITH TIME ZONE` value is read in the session time zone, which is UTC. If `ts` is `NULL`, the result is `NULL`.

### Syntax
<a name="athena-duckdb-functions-date-time-monthname-syntax"></a>

```sql
monthname({{ts}})
```

### Arguments
<a name="athena-duckdb-functions-date-time-monthname-arguments"></a>

The `monthname` function takes the following argument:

**{{ts}}**  
The value to read the month from, as a `DATE`, `TIMESTAMP`, or `TIMESTAMP WITH TIME ZONE` value.

### Return type
<a name="athena-duckdb-functions-date-time-monthname-return-type"></a>

`VARCHAR`

### Examples
<a name="athena-duckdb-functions-date-time-monthname-examples"></a>

The following SQL query returns the name of the month of a timestamp.

```sql
SELECT monthname(TIMESTAMP '1992-09-20') AS result
```

The query returns the following result.


| result | 
| --- | 
| `September` | 

The following SQL query reads a timestamp with time zone in UTC, and then in a time zone that is 5 hours behind UTC on that date. The two months differ.

```sql
SELECT
    monthname(
        TIMESTAMPTZ '2021-08-31 23:30:00-05'
    ) AS utc_month,
    monthname(
        TIMESTAMPTZ '2021-08-31 23:30:00-05' AT TIME ZONE 'America/Chicago'
    ) AS local_month
```

The query returns the following result.


| utc\_month | local\_month | 
| --- | --- | 
| `September` | `August` | 

### Considerations
<a name="athena-duckdb-functions-date-time-monthname-considerations"></a>

`monthname` does not accept a string. Cast a string to `DATE` or `TIMESTAMP` first.

### Differences from Athena engine version 3
<a name="athena-duckdb-functions-date-time-monthname-differences-from-engine-version-3"></a>

In Athena engine version 3, you get the English month name with `date_format({{ts}}, '%M')`. DuckDB has no `date_format` function, and in `strftime`, `%M` is the minute, not the month name. Replace the call with `monthname({{ts}})` or `strftime({{ts}}, '%B')`.

## `nanosecond` function
<a name="athena-duckdb-functions-date-time-nanosecond"></a>

Returns the seconds part of `ts`, including its fraction, as a number of nanoseconds. The result is from `0` to `59999999999`, so `11:59:44.123456789` gives `44123456789`. For a `DATE`, the result is `0`.

Only `TIMESTAMP_NS`, `TIMESTAMPTZ_NS`, and `TIME_NS` values hold nanoseconds. Other types hold at most microseconds, so for them the last three digits of the result are always `0`. If `ts` is `NULL`, the result is `NULL`.

### Syntax
<a name="athena-duckdb-functions-date-time-nanosecond-syntax"></a>

```sql
nanosecond({{ts}})
```

### Arguments
<a name="athena-duckdb-functions-date-time-nanosecond-arguments"></a>

The `nanosecond` function takes the following argument:

**{{ts}}**  
The value to read the seconds and fractional seconds from, as a `DATE`, `TIME`, `TIME_NS`, `TIME WITH TIME ZONE`, `TIMESTAMP`, `TIMESTAMP WITH TIME ZONE`, `TIMESTAMP_NS`, `TIMESTAMPTZ_NS`, or `INTERVAL` value.

### Return type
<a name="athena-duckdb-functions-date-time-nanosecond-return-type"></a>

`BIGINT`

### Examples
<a name="athena-duckdb-functions-date-time-nanosecond-examples"></a>

The following SQL query returns the seconds of a `TIMESTAMP_NS` value in nanoseconds.

```sql
SELECT
    nanosecond(
        TIMESTAMP_NS '2021-08-03 11:59:44.123456789'
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `44123456789` | 

The following SQL query passes a `TIMESTAMP` value, which holds microseconds, so the last three digits of the result are `0`.

```sql
SELECT
    nanosecond(
        TIMESTAMP '2021-08-03 11:59:44.123456'
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `44123456000` | 

The following SQL query returns only the fractional part of the second, in nanoseconds.

```sql
SELECT
    nanosecond(
        TIMESTAMP_NS '2021-08-03 11:59:44.123456789'
    ) % 1000000000 AS result
```

The query returns the following result.


| result | 
| --- | 
| `123456789` | 

### Considerations
<a name="athena-duckdb-functions-date-time-nanosecond-considerations"></a>

To get only the fractional part of the second, from `0` to `999999999`, use `nanosecond({{ts}}) % 1000000000`.

## `quarter` function
<a name="athena-duckdb-functions-date-time-quarter"></a>

Returns the calendar quarter that `value` falls in, as a number from `1` to `4`. January through March is quarter `1`, and October through December is quarter `4`. If `value` is `NULL`, the result is `NULL`.

For an `INTERVAL`, the function uses only the months that remain after whole years are removed, and ignores days and smaller units. For example, `quarter(INTERVAL '7 months')` returns `3`, and `quarter(INTERVAL '14 months')` returns `1`. A negative interval can give a result outside the range from `1` to `4`, such as `0` for `INTERVAL '-3 months'` and `-1` for `INTERVAL '-7 months'`.

`quarter({{value}})` returns the same result as `extract(quarter FROM {{value}})` and `date_part('quarter', {{value}})`.

### Syntax
<a name="athena-duckdb-functions-date-time-quarter-syntax"></a>

```sql
quarter({{value}})
```

### Arguments
<a name="athena-duckdb-functions-date-time-quarter-arguments"></a>

The `quarter` function takes the following argument:

**{{value}}**  
The value to read the quarter from, as a `DATE`, `TIMESTAMP`, `TIMESTAMP WITH TIME ZONE`, or `INTERVAL` value.

### Return type
<a name="athena-duckdb-functions-date-time-quarter-return-type"></a>

`BIGINT`

### Examples
<a name="athena-duckdb-functions-date-time-quarter-examples"></a>

The following SQL query returns the quarter of a timestamp in August.

```sql
SELECT
    quarter(
        TIMESTAMP '2021-08-03 11:59:44.123456'
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `3` | 

The following SQL query returns the quarter of dates at the start and end of quarters.

```sql
SELECT d AS order_date, quarter(d) AS order_quarter
FROM (VALUES
    (DATE '2024-01-01'),
    (DATE '2024-03-31'),
    (DATE '2024-04-01'),
    (DATE '2024-12-31')
) AS v(d)
ORDER BY d
```

The query returns the following results.


| order\_date | order\_quarter | 
| --- | --- | 
| `2024-01-01` | `1` | 
| `2024-03-31` | `1` | 
| `2024-04-01` | `2` | 
| `2024-12-31` | `4` | 

The following SQL query passes 23:30 on March 31 at a UTC offset of `-05`. In UTC, that is 04:30 on April 1, so the function returns quarter `2`.

```sql
SELECT
    quarter(
        TIMESTAMPTZ '2024-03-31 23:30:00-05'
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `2` | 

The following SQL query returns the quarter for two intervals. The 14-month interval counts as 2 months after the whole year is removed.

```sql
SELECT
    quarter(INTERVAL '7 months') AS seven_months,
    quarter(INTERVAL '14 months') AS fourteen_months
```

The query returns the following result.


| seven\_months | fourteen\_months | 
| --- | --- | 
| `3` | `1` | 

### Considerations
<a name="athena-duckdb-functions-date-time-quarter-considerations"></a>

Pass a typed value. A string, such as `quarter('2024-05-05')`, makes the query fail. Write a typed literal such as `DATE '2024-05-05'`, or cast the string to `DATE` or `TIMESTAMP` first.

For a `TIMESTAMP WITH TIME ZONE` value, the function computes the quarter in the session time zone, which is UTC. A time late on the last day of a quarter in a zone west of UTC can belong to the next quarter.

## `second` function
<a name="athena-duckdb-functions-date-time-second"></a>

Returns the seconds part of `value` as a whole number. For a time or timestamp, the result is from `0` to `59`, and any fraction of a second is dropped, not rounded. For a `DATE`, the result is `0`. If `value` is `NULL`, the result is `NULL`.

For an `INTERVAL`, the function returns the seconds that remain after whole minutes are removed, so `second(INTERVAL '90 seconds')` returns `30`. A negative interval gives a negative result.

`second({{value}})` returns the same result as `extract(second FROM {{value}})`. To keep the fraction, use the [`millisecond` function](#athena-duckdb-functions-date-time-millisecond) or the [`microsecond` function](#athena-duckdb-functions-date-time-microsecond), whose results include the whole seconds.

### Syntax
<a name="athena-duckdb-functions-date-time-second-syntax"></a>

```sql
second({{value}})
```

### Arguments
<a name="athena-duckdb-functions-date-time-second-arguments"></a>

The `second` function takes the following argument:

**{{value}}**  
The value to read the seconds from, as a `TIME`, `TIME WITH TIME ZONE`, `DATE`, `TIMESTAMP`, `TIMESTAMP WITH TIME ZONE`, or `INTERVAL` value.

### Return type
<a name="athena-duckdb-functions-date-time-second-return-type"></a>

`BIGINT`

### Examples
<a name="athena-duckdb-functions-date-time-second-examples"></a>

The following SQL query returns the seconds part of a timestamp.

```sql
SELECT
    second(
        TIMESTAMP '2021-08-03 11:59:44.123456'
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `44` | 

The following SQL query shows that the fraction is dropped, not rounded. `millisecond` returns the seconds and the fraction together, in milliseconds.

```sql
SELECT
    second(
        TIMESTAMP '2021-08-03 11:59:44.987654'
    ) AS seconds,
    millisecond(
        TIMESTAMP '2021-08-03 11:59:44.987654'
    ) AS milliseconds
```

The query returns the following result.


| seconds | milliseconds | 
| --- | --- | 
| `44` | `44987` | 

The following SQL query returns the seconds part of a 90-second interval, which is 1 minute and 30 seconds.

```sql
SELECT second(INTERVAL '90 seconds') AS result
```

The query returns the following result.


| result | 
| --- | 
| `30` | 

## `year` function
<a name="athena-duckdb-functions-date-time-year"></a>

Returns the calendar year of `ts`. If `ts` is `NULL`, the result is `NULL`.

For an `INTERVAL`, `year` returns the number of whole years in its months part, so `INTERVAL 30 MONTH` gives `2`. Days and smaller units are not converted to years, so `INTERVAL 400 DAY` gives `0`.

`year` returns the calendar year. To get the year that an ISO 8601 week belongs to, use the [`isoyear` function](duckdb-functions-date-time-weeks-and-weekdays.md#athena-duckdb-functions-date-time-isoyear).

### Syntax
<a name="athena-duckdb-functions-date-time-year-syntax"></a>

```sql
year({{ts}})
```

### Arguments
<a name="athena-duckdb-functions-date-time-year-arguments"></a>

The `year` function takes the following argument:

**{{ts}}**  
The value to read the year from, as a `DATE`, `TIMESTAMP`, `TIMESTAMP WITH TIME ZONE`, or `INTERVAL` value. Nanosecond values, `TIMESTAMP_NS` and `TIMESTAMPTZ_NS`, are accepted too.

### Return type
<a name="athena-duckdb-functions-date-time-year-return-type"></a>

`BIGINT`

### Examples
<a name="athena-duckdb-functions-date-time-year-examples"></a>

The following SQL query returns the year of a timestamp.

```sql
SELECT
    year(
        TIMESTAMP '2021-08-03 11:59:44.123456'
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `2021` | 

The following SQL query compares the calendar year with the ISO year for January 1, 2021, which is in the last ISO week of 2020.

```sql
SELECT
    year(DATE '2021-01-01') AS calendar_year,
    isoyear(DATE '2021-01-01') AS iso_year
```

The query returns the following result.


| calendar\_year | iso\_year | 
| --- | --- | 
| `2021` | `2020` | 

The following SQL query returns the number of whole years in an interval of 30 months.

```sql
SELECT year(INTERVAL 30 MONTH) AS result
```

The query returns the following result.


| result | 
| --- | 
| `2` | 

The following SQL query passes 11:30 PM on December 31, 2021, at UTC offset -05. In UTC, that time is in 2022.

```sql
SELECT
    year(TIMESTAMPTZ '2021-12-31 23:30:00-05') AS result
```

The query returns the following result.


| result | 
| --- | 
| `2022` | 

### Considerations
<a name="athena-duckdb-functions-date-time-year-considerations"></a>

For a `TIMESTAMP WITH TIME ZONE` value, the year is taken in the session time zone, which is UTC. A time late on December 31 in a time zone west of UTC can already be in the next year.

Pass a date or timestamp, not a string. A call such as `year('2021-08-03')` fails. Write `year(DATE '2021-08-03')`, or cast the string to `DATE`.