

# Interval functions

Use these functions to build an `INTERVAL` from a number of units, such as days, hours, or months, and to rewrite an interval in larger units. Add an interval to a date or timestamp with the [`+` (addition) operator](duckdb-functions-numeric-arithmetic-operators.md#athena-duckdb-functions-numeric-addition-operator), or subtract it with the [`-` (subtraction and negation) operator](duckdb-functions-numeric-arithmetic-operators.md#athena-duckdb-functions-numeric-subtraction-operator).

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

Returns an `INTERVAL` that is equal to `interval`, with its parts rewritten. Each whole 24 hours in the time part moves to the days part, and then each whole 30 days moves to the months part. For example, `INTERVAL '36 hours'` becomes `1 day 12:00:00`, and `INTERVAL '45 days'` becomes `1 month 15 days`.

If `interval` is `NULL`, the result is `NULL`.

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

```sql
normalized_interval({{interval}})
```

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

The `normalized_interval` function takes the following argument:

**{{interval}}**  
The interval to rewrite, as an `INTERVAL` value.

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

`INTERVAL`

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

The following SQL query rewrites an interval of 30 days as 1 month.

```sql
SELECT normalized_interval(INTERVAL '30 days') AS result
```

The query returns the following result.


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

The following SQL query shows an interval of 36 hours before and after normalization.

```sql
SELECT
    INTERVAL '36 hours' AS original,
    normalized_interval(
        INTERVAL '36 hours'
    ) AS normalized
```

The query returns the following result.


| original | normalized | 
| --- | --- | 
| `36:00:00` | `1 day 12:00:00` | 

The following SQL query adds 30 days to January 31, 2024, first as days and then as the normalized interval of 1 month. The two results differ by one day.

```sql
SELECT
    DATE '2024-01-31' + INTERVAL '30 days' AS days_added,
    DATE '2024-01-31' + normalized_interval(
        INTERVAL '30 days'
    ) AS normalized_added
```

The query returns the following result.


| days\_added | normalized\_added | 
| --- | --- | 
| `2024-03-01 00:00:00` | `2024-02-29 00:00:00` | 

The following SQL query normalizes a negative interval. The months part is negative and the days part is positive.

```sql
SELECT
    normalized_interval(INTERVAL '-45 days') AS result
```

The query returns the following result.


| result | 
| --- | 
| `-2 months 15 days` | 

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

Comparisons already treat 30 days as equal to 1 month and 24 hours as equal to 1 day, so the result compares equal to the input. Date arithmetic does not treat them as equal. Adding `1 month` moves to the same day of the next month, or to the last day of the next month when that month has no such day. Adding `30 days` moves exactly 30 days. Adding a normalized interval to a date can give a different result from adding the original interval.

For a negative interval, the parts of the result can have different signs. For example, `INTERVAL '-45 days'` becomes `-2 months 15 days`, which is still equal to 45 days back.

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

Returns an `INTERVAL` of `integer` centuries, where each century is 100 years. Add the result to a date or timestamp to move it forward by that many centuries, or subtract it to move back. A negative `integer` gives a negative interval. If `integer` is `NULL`, the result is `NULL`.

The interval is shown in years, so `to_centuries(5)` is shown as `500 years`. To build intervals in other units, use `to_millennia`, `to_decades`, or `to_years`.

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

```sql
to_centuries({{integer}})
```

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

The `to_centuries` function takes the following argument:

**{{integer}}**  
The number of centuries, as an `INTEGER` or `BIGINT` value.

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

`INTERVAL`

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

The following SQL query returns an interval of five centuries.

```sql
SELECT to_centuries(5) AS result
```

The query returns the following result.


| result | 
| --- | 
| `500 years` | 

The following SQL query adds one century to February 29, 2000. The year 2100 is not a leap year, so the result is February 28.

```sql
SELECT
    CAST(
        DATE '2000-02-29' + to_centuries(1) AS DATE
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `2100-02-28` | 

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

The argument must be a whole number. A call with a decimal value, such as `to_centuries(2.5)`, fails. Cast the value to `INTEGER` first. The cast rounds to the nearest whole number. A `DECIMAL` value exactly halfway between two whole numbers, such as `2.5`, rounds away from zero, to `3`. A `DOUBLE` value exactly halfway rounds to the even number, so `CAST(2.5e0 AS INTEGER)` returns `2`.

The interval is stored as a number of months. When you add it to February 29 and the target year is not a leap year, the result is February 28.

Adding an interval to a `DATE` returns a `TIMESTAMP`. To keep a `DATE`, cast the result.

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

Returns an `INTERVAL` of `integer` days. Add the result to a date or timestamp to move it forward by that many days, or subtract it to move back. A negative `integer` gives a negative interval. If `integer` is `NULL`, the result is `NULL`.

The days are not converted to months, so `to_days(45)` is shown as `45 days`. To build intervals in other units, use `to_weeks`, `to_hours`, or `to_months`.

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

```sql
to_days({{integer}})
```

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

The `to_days` function takes the following argument:

**{{integer}}**  
The number of days, as an `INTEGER` or `BIGINT` value from `-2147483648` to `2147483647`.

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

`INTERVAL`

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

The following SQL query returns an interval of five days.

```sql
SELECT to_days(5) AS result
```

The query returns the following result.


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

The following SQL query adds 30 days to a date. The sum is a `TIMESTAMP`, so the second column casts it to `DATE`.

```sql
SELECT
    DATE '2024-01-31' + to_days(30) AS plus_days,
    CAST(
        DATE '2024-01-31' + to_days(30) AS DATE
    ) AS plus_days_date
```

The query returns the following result.


| plus\_days | plus\_days\_date | 
| --- | --- | 
| `2024-03-01 00:00:00` | `2024-03-01` | 

The following SQL query shows that 45 days stays 45 days. It is not converted to months.

```sql
SELECT to_days(45) AS result
```

The query returns the following result.


| result | 
| --- | 
| `45 days` | 

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

The argument must be a whole number. A call with a decimal value, such as `to_days(2.5)`, fails. Cast the value to `INTEGER` first. The cast rounds to the nearest whole number. A `DECIMAL` value exactly halfway between two whole numbers, such as `2.5`, rounds away from zero, to `3`. A `DOUBLE` value exactly halfway rounds to the even number, so `CAST(2.5e0 AS INTEGER)` returns `2`.

A value outside the range of a 32-bit integer makes the query fail.

Adding an interval to a `DATE` returns a `TIMESTAMP`. To keep a `DATE`, cast the result, as in `CAST(DATE '2024-01-31' + to_days(30) AS DATE)`.

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

Returns an `INTERVAL` of `integer` decades, where each decade is 10 years. Add the result to a date or timestamp to move it forward by that many decades, or subtract it to move back. A negative `integer` gives a negative interval. If `integer` is `NULL`, the result is `NULL`.

The interval is shown in years, so `to_decades(5)` is shown as `50 years`. To build intervals in other units, use the [`to_centuries` function](#athena-duckdb-functions-date-time-to-centuries) or the [`to_years` function](#athena-duckdb-functions-date-time-to-years).

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

```sql
to_decades({{integer}})
```

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

The `to_decades` function takes the following argument:

**{{integer}}**  
The number of decades, as an `INTEGER` or `BIGINT` value.

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

`INTERVAL`

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

The following SQL query returns an interval of five decades.

```sql
SELECT to_decades(5) AS result
```

The query returns the following result.


| result | 
| --- | 
| `50 years` | 

The following SQL query adds one decade to February 29, 2024. The year 2034 is not a leap year, so the result is February 28.

```sql
SELECT
    CAST(
        DATE '2024-02-29' + to_decades(1) AS DATE
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `2034-02-28` | 

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

The argument must be a whole number. A call with a decimal value, such as `to_decades(2.5)`, fails. Cast the value to `INTEGER` first. The cast rounds to the nearest whole number. A `DECIMAL` value exactly halfway between two whole numbers, such as `2.5`, rounds away from zero, to `3`. A `DOUBLE` value exactly halfway rounds to the even number, so `CAST(2.5e0 AS INTEGER)` returns `2`.

The interval is stored as a number of months. When you add it to February 29 and the target year is not a leap year, the result is February 28.

Adding an interval to a `DATE` returns a `TIMESTAMP`. To keep a `DATE`, cast the result.

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

Returns an `INTERVAL` of `integer` hours. Add the result to a time or timestamp to move it forward by that many hours, or subtract it to move back. A negative `integer` gives a negative interval. If `integer` is `NULL`, the result is `NULL`.

The hours are not converted to days, so `to_hours(36)` is shown as `36:00:00`. The interval still compares as equal to `INTERVAL '1 day 12 hours'`. To build intervals in other units, use `to_days`, `to_minutes`, or `to_seconds`.

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

```sql
to_hours({{integer}})
```

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

The `to_hours` function takes the following argument:

**{{integer}}**  
The number of hours, as a `BIGINT` value.

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

`INTERVAL`

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

The following SQL query returns an interval of five hours.

```sql
SELECT to_hours(5) AS result
```

The query returns the following result.


| result | 
| --- | 
| `05:00:00` | 

The following SQL query shows that `to_hours(36)` displays as 36 hours, not as 1 day and 12 hours. The value still compares as equal to `INTERVAL '1 day 12 hours'`.

```sql
SELECT
    to_hours(36) AS result,
    to_hours(36) = INTERVAL '1 day 12 hours' AS is_equal
```

The query returns the following result.


| result | is\_equal | 
| --- | --- | 
| `36:00:00` | `true` | 

The following SQL query adds five hours to a timestamp late in the day, which moves it to the next day.

```sql
SELECT
    TIMESTAMP '2024-05-01 22:00:00' + to_hours(5) AS result
```

The query returns the following result.


| result | 
| --- | 
| `2024-05-02 03:00:00` | 

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

The argument must be a whole number. A call with a decimal value, such as `to_hours(1.5)`, fails. For a fraction of an hour, use a smaller unit, such as `to_minutes(90)`.

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

Returns an `INTERVAL` of `integer` microseconds. A microsecond is the smallest unit that an interval can hold. A negative `integer` gives a negative interval. If `integer` is `NULL`, the result is `NULL`.

The interval is shown as hours, minutes, and seconds with a fraction, so `to_microseconds(1500000)` is shown as `00:00:01.5`. To build intervals in other units, use the [`to_milliseconds` function](#athena-duckdb-functions-date-time-to-milliseconds) or the [`to_seconds` function](#athena-duckdb-functions-date-time-to-seconds).

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

```sql
to_microseconds({{integer}})
```

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

The `to_microseconds` function takes the following argument:

**{{integer}}**  
The number of microseconds, as a `BIGINT` value.

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

`INTERVAL`

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

The following SQL query returns an interval of five microseconds.

```sql
SELECT to_microseconds(5) AS result
```

The query returns the following result.


| result | 
| --- | 
| `00:00:00.000005` | 

The following SQL query adds 250 microseconds to a timestamp.

```sql
SELECT
    TIMESTAMP '2024-05-01 10:00:00' + to_microseconds(250) AS result
```

The query returns the following result.


| result | 
| --- | 
| `2024-05-01 10:00:00.00025` | 

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

The argument must be a whole number. A call with a decimal value, such as `to_microseconds(1.5)`, fails.

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

Returns an `INTERVAL` of `integer` millennia, where each millennium is 1,000 years. Add the result to a date or timestamp to move it forward by that many millennia, or subtract it to move back. A negative `integer` gives a negative interval. If `integer` is `NULL`, the result is `NULL`.

The interval is shown in years, so `to_millennia(1)` is shown as `1000 years`. To build intervals in other units, use the [`to_centuries` function](#athena-duckdb-functions-date-time-to-centuries) or the [`to_years` function](#athena-duckdb-functions-date-time-to-years).

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

```sql
to_millennia({{integer}})
```

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

The `to_millennia` function takes the following argument:

**{{integer}}**  
The number of millennia, as an `INTEGER` or `BIGINT` value.

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

`INTERVAL`

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

The following SQL query returns an interval of one millennium.

```sql
SELECT to_millennia(1) AS result
```

The query returns the following result.


| result | 
| --- | 
| `1000 years` | 

The following SQL query subtracts one millennium from a date and casts the result to `DATE`.

```sql
SELECT
    CAST(
        DATE '2024-05-01' - to_millennia(1) AS DATE
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `1024-05-01` | 

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

The argument must be a whole number. A call with a decimal value, such as `to_millennia(1.5)`, fails. Cast the value to `INTEGER` first. The cast rounds to the nearest whole number. A `DECIMAL` value exactly halfway between two whole numbers, such as `2.5`, rounds away from zero, to `3`. A `DOUBLE` value exactly halfway rounds to the even number, so `CAST(2.5e0 AS INTEGER)` returns `2`.

Adding an interval to a `DATE` returns a `TIMESTAMP`. To keep a `DATE`, cast the result.

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

Returns an `INTERVAL` of `double` milliseconds. Unlike `to_microseconds`, `to_minutes`, and `to_hours`, this function accepts a fraction, so `to_milliseconds(5.5)` is 5,500 microseconds. A negative value gives a negative interval. If `double` is `NULL`, the result is `NULL`.

The interval is shown as hours, minutes, and seconds with a fraction, so `to_milliseconds(1500)` is shown as `00:00:01.5`. To build intervals in other units, use the [`to_microseconds` function](#athena-duckdb-functions-date-time-to-microseconds) or the [`to_seconds` function](#athena-duckdb-functions-date-time-to-seconds).

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

```sql
to_milliseconds({{double}})
```

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

The `to_milliseconds` function takes the following argument:

**{{double}}**  
The number of milliseconds, as a `DOUBLE` value. It can be negative and can have a fractional part.

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

`INTERVAL`

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

The following SQL query returns an interval of 5.5 milliseconds.

```sql
SELECT to_milliseconds(5.5) AS result
```

The query returns the following result.


| result | 
| --- | 
| `00:00:00.0055` | 

The following SQL query returns an interval of 1,500 milliseconds, which is shown as 1.5 seconds.

```sql
SELECT to_milliseconds(1500) AS result
```

The query returns the following result.


| result | 
| --- | 
| `00:00:01.5` | 

The following SQL query adds 1,500 milliseconds to a timestamp.

```sql
SELECT
    TIMESTAMP '2024-05-01 10:00:00' + to_milliseconds(1500) AS result
```

The query returns the following result.


| result | 
| --- | 
| `2024-05-01 10:00:01.5` | 

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

An interval holds whole microseconds, so the result is rounded to the nearest microsecond. For example, `to_milliseconds(0.0004)` is an interval of zero.

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

Returns an `INTERVAL` of `integer` minutes. Add the result to a time or timestamp to move it forward by that many minutes, or subtract it to move back. A negative `integer` gives a negative interval. If `integer` is `NULL`, the result is `NULL`.

The interval is shown as hours, minutes, and seconds, so `to_minutes(90)` is shown as `01:30:00`. To build intervals in other units, use the [`to_hours` function](#athena-duckdb-functions-date-time-to-hours) or the [`to_seconds` function](#athena-duckdb-functions-date-time-to-seconds).

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

```sql
to_minutes({{integer}})
```

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

The `to_minutes` function takes the following argument:

**{{integer}}**  
The number of minutes, as a `BIGINT` value.

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

`INTERVAL`

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

The following SQL query returns an interval of five minutes.

```sql
SELECT to_minutes(5) AS result
```

The query returns the following result.


| result | 
| --- | 
| `00:05:00` | 

The following SQL query returns an interval of 90 minutes, which is shown as 1 hour and 30 minutes.

```sql
SELECT to_minutes(90) AS result
```

The query returns the following result.


| result | 
| --- | 
| `01:30:00` | 

The following SQL query subtracts 90 minutes from a timestamp.

```sql
SELECT
    TIMESTAMP '2024-05-01 10:00:00' - to_minutes(90) AS result
```

The query returns the following result.


| result | 
| --- | 
| `2024-05-01 08:30:00` | 

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

The argument must be a whole number. A call with a decimal value, such as `to_minutes(1.5)`, fails. For a fraction of a minute, use the [`to_seconds` function](#athena-duckdb-functions-date-time-to-seconds), which accepts a fraction.

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

Returns an `INTERVAL` of `integer` months. Add the result to a date or timestamp to move it forward by that many months, or subtract it to move back. A negative `integer` gives a negative interval. If `integer` is `NULL`, the result is `NULL`.

The interval is shown in years and months, so 14 months is shown as `1 year 2 months`. To build intervals in other units, use functions such as `to_years`, `to_quarters`, `to_weeks`, `to_days`, `to_hours`, `to_minutes`, or `to_seconds`.

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

```sql
to_months({{integer}})
```

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

The `to_months` function takes the following argument:

**{{integer}}**  
The number of months, as an `INTEGER` or `BIGINT` value.

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

`INTERVAL`

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

The following SQL query returns an interval of 5 months.

```sql
SELECT to_months(5) AS result
```

The query returns the following result.


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

The following SQL query returns an interval of 14 months, which is shown in years and months.

```sql
SELECT to_months(14) AS result
```

The query returns the following result.


| result | 
| --- | 
| `1 year 2 months` | 

The following SQL query adds one month to January 31. February has no 31st day, so the result is the last day of February. The result is a `TIMESTAMP`, not a `DATE`.

```sql
SELECT DATE '2026-01-31' + to_months(1) AS result
```

The query returns the following result.


| result | 
| --- | 
| `2026-02-28 00:00:00` | 

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

The argument must be a whole number. A call with a decimal value, such as `to_months(2.5)`, fails. Cast the value to `INTEGER` first. The cast rounds to the nearest whole number.

When you add months to a date and the day does not exist in the target month, the result is the last day of that month. For example, January 31 plus one month is February 28 in a year that is not a leap year.

Adding an interval to a `DATE` returns a `TIMESTAMP`. To keep a `DATE`, cast the result, as in `CAST(DATE '2026-01-31' + to_months(1) AS DATE)`.

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

Returns an `INTERVAL` of `integer` quarters. Each quarter is three months. The interval is stored as months and shown in years and months, so `to_quarters(5)` is shown as `1 year 3 months`. A negative `integer` gives a negative interval. If `integer` is `NULL`, the result is `NULL`.

`to_quarters({{integer}})` returns the same interval as `to_months(3 * {{integer}})`.

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

```sql
to_quarters({{integer}})
```

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

The `to_quarters` function takes the following argument:

**{{integer}}**  
The number of quarters, as an `INTEGER` or `BIGINT` value.

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

`INTERVAL`

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

The following SQL query returns an interval of 5 quarters, which is 15 months and is shown in years and months.

```sql
SELECT to_quarters(5) AS result
```

The query returns the following result.


| result | 
| --- | 
| `1 year 3 months` | 

The following SQL query adds one quarter to a date.

```sql
SELECT DATE '2026-01-15' + to_quarters(1) AS result
```

The query returns the following result.


| result | 
| --- | 
| `2026-04-15 00:00:00` | 

The following SQL query shows that one quarter equals three months.

```sql
SELECT to_quarters(1) = to_months(3) AS is_equal
```

The query returns the following result.


| is\_equal | 
| --- | 
| `true` | 

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

The argument must be a whole number. A call with a decimal value, such as `to_quarters(2.5)`, fails.

When you add quarters to a date and the day does not exist in the target month, the result is the last day of that month, as with `to_months`. Adding an interval to a `DATE` returns a `TIMESTAMP`.

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

Returns an `INTERVAL` of `double` seconds. The value can have a fractional part, so you can also use `to_seconds` for intervals of milliseconds or microseconds. A negative value gives a negative interval. If `double` is `NULL`, the result is `NULL`.

The interval is shown as hours, minutes, and seconds, in the form `HH:MM:SS`, followed by any fraction of a second.

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

```sql
to_seconds({{double}})
```

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

The `to_seconds` function takes the following argument:

**{{double}}**  
The number of seconds, as a `DOUBLE` value. It can be negative and can have a fractional part.

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

`INTERVAL`

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

The following SQL query returns an interval of 5.5 seconds.

```sql
SELECT to_seconds(5.5) AS result
```

The query returns the following result.


| result | 
| --- | 
| `00:00:05.5` | 

The following SQL query converts 96 seconds to an interval and casts it to text.

```sql
SELECT CAST(to_seconds(96) AS VARCHAR) AS result
```

The query returns the following result.


| result | 
| --- | 
| `00:01:36` | 

The following SQL query shows that 90,000 seconds stay in hours and are not converted to days.

```sql
SELECT to_seconds(90000) AS result
```

The query returns the following result.


| result | 
| --- | 
| `25:00:00` | 

The following SQL query adds 90 seconds to a timestamp.

```sql
SELECT
    TIMESTAMP '2026-01-01 00:00:00' + to_seconds(90) AS result
```

The query returns the following result.


| result | 
| --- | 
| `2026-01-01 00:01:30` | 

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

The interval keeps the seconds as a span of time and does not convert them to days, so `to_seconds(90000)` is shown as `25:00:00`. When you compare intervals, 24 hours equals one day, so `to_seconds(86400) = INTERVAL 1 DAY` is `true`.

The interval has microsecond precision. A fraction smaller than one microsecond is rounded to the nearest microsecond.

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

Athena engine version 3 has `human_readable_seconds`, which formats a number of seconds as text such as `1 minute, 36 seconds`. DuckDB does not have this function. The closest replacement is `CAST(to_seconds({{n}}) AS VARCHAR)`, which returns text such as `00:01:36`.

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

Returns an `INTERVAL` of `integer` weeks. Each week is stored as 7 days, so the interval is shown in days: `to_weeks(5)` is shown as `35 days`. A negative `integer` gives a negative interval. If `integer` is `NULL`, the result is `NULL`.

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

```sql
to_weeks({{integer}})
```

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

The `to_weeks` function takes the following argument:

**{{integer}}**  
The number of weeks, as an `INTEGER` or `BIGINT` value.

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

`INTERVAL`

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

The following SQL query returns an interval of 5 weeks, which is shown as 35 days.

```sql
SELECT to_weeks(5) AS result
```

The query returns the following result.


| result | 
| --- | 
| `35 days` | 

The following SQL query adds two weeks to a date. The result is a `TIMESTAMP`.

```sql
SELECT DATE '2026-11-18' + to_weeks(2) AS result
```

The query returns the following result.


| result | 
| --- | 
| `2026-12-02 00:00:00` | 

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

The argument must be a whole number. A call with a decimal value, such as `to_weeks(2.5)`, fails.

Adding an interval to a `DATE` returns a `TIMESTAMP`. To keep a `DATE`, cast the result to `DATE`.

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

Returns an `INTERVAL` of `integer` years. The interval is stored as 12 months for each year. A negative `integer` gives a negative interval. If `integer` is `NULL`, the result is `NULL`.

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

```sql
to_years({{integer}})
```

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

The `to_years` function takes the following argument:

**{{integer}}**  
The number of years, as an `INTEGER` or `BIGINT` value.

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

`INTERVAL`

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

The following SQL query returns an interval of 5 years.

```sql
SELECT to_years(5) AS result
```

The query returns the following result.


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

The following SQL query adds one year to February 29, 2024. The year 2025 is not a leap year, so the result is February 28, 2025.

```sql
SELECT DATE '2024-02-29' + to_years(1) AS result
```

The query returns the following result.


| result | 
| --- | 
| `2025-02-28 00:00:00` | 

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

The argument must be a whole number. A call with a decimal value, such as `to_years(2.5)`, fails.

When you add years to February 29 and the target year is not a leap year, the result is February 28.

Adding an interval to a `DATE` returns a `TIMESTAMP`. To keep a `DATE`, cast the result to `DATE`.