

# Week and weekday functions

Use these functions to get the day of the week as a number or a name, and to number the weeks of the year. Week numbers and week-numbering years follow ISO 8601, where weeks start on Monday and week 1 contains the first Thursday of the year.

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

Returns the name of the day of the week of `value`, in English with an initial capital letter, such as `Sunday`. If `value` is `NULL`, the result is `NULL`.

To get the day of the week as a number, use the [`dayofweek` function](#athena-duckdb-functions-date-time-dayofweek) or the [`isodow` function](#athena-duckdb-functions-date-time-isodow). The `dayofweek` function numbers Sunday as 0, and the `isodow` function numbers Monday as 1 and Sunday as 7.

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

```sql
dayname({{value}})
```

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

The `dayname` function takes the following argument:

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

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

`VARCHAR`

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

The following SQL query returns the name of the day of the week of March 22, 1992.

```sql
SELECT dayname(TIMESTAMP '1992-03-22') AS result
```

The query returns the following result.


| result | 
| --- | 
| `Sunday` | 

The following SQL query shows that a lowercase name does not match unless you apply `lower` first.

```sql
SELECT
    dayname(
        DATE '2026-11-18'
    ) = 'wednesday' AS lowercase_match,
    lower(
        dayname(DATE '2026-11-18')
    ) = 'wednesday' AS lower_match
```

The query returns the following result.


| lowercase\_match | lower\_match | 
| --- | --- | 
| `false` | `true` | 

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

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

The query returns the following result.


| result | 
| --- | 
| `Thursday` | 

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

Comparisons of the name with a string are case-sensitive, so compare with `'Monday'`, not `'monday'`, or apply `lower` to the name first.

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.

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

Returns the day of the week of `ts`, where `0` is Sunday, `1` is Monday, and `6` is Saturday. If `ts` is `NULL`, the result is `NULL`.

The `weekday` function returns the same result. For the ISO 8601 numbering, where Monday is `1` and Sunday is `7`, use the [`isodow` function](#athena-duckdb-functions-date-time-isodow). To get the name of the day, use the [`dayname` function](#athena-duckdb-functions-date-time-dayname).

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

```sql
dayofweek({{ts}})
```

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

The `dayofweek` function takes the following argument:

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

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

`BIGINT`

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

The following SQL query returns the day of the week of a timestamp. August 3, 2021, is a Tuesday, so the function returns `2`.

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

The query returns the following result.


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

The following SQL query returns the numbers for a Sunday and a Saturday. Sunday is `0`, not `7`.

```sql
SELECT
    dayofweek(DATE '2021-03-07') AS sunday,
    dayofweek(DATE '2021-03-13') AS saturday
```

The query returns the following result.


| sunday | saturday | 
| --- | --- | 
| `0` | `6` | 

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

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

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

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

In Athena engine version 3, `day_of_week` returns `1` for Monday through `7` for Sunday. DuckDB does not have `day_of_week`, and `dayofweek` returns `0` for Sunday. For the Athena engine version 3 numbering, use the [`isodow` function](#athena-duckdb-functions-date-time-isodow).

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

Returns the ISO 8601 day of the week of `ts`, where `1` is Monday and `7` is Sunday. If `ts` is `NULL`, the result is `NULL`.

`isodow` and `dayofweek` differ only for Sunday: `isodow` returns `7`, and `dayofweek` returns `0`.

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

```sql
isodow({{ts}})
```

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

The `isodow` function takes the following argument:

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

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

`BIGINT`

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

The following SQL query returns the ISO 8601 day of the week of a timestamp. August 3, 2021, is a Tuesday, so the function returns `2`.

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

The query returns the following result.


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

The following SQL query compares `isodow` and `dayofweek` for a Sunday.

```sql
SELECT
    isodow(DATE '2021-03-07') AS isodow_sunday,
    dayofweek(DATE '2021-03-07') AS dayofweek_sunday
```

The query returns the following result.


| isodow\_sunday | dayofweek\_sunday | 
| --- | --- | 
| `7` | `0` | 

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

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

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

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

Athena engine version 3 uses `day_of_week` for the ISO 8601 day of the week. DuckDB does not have `day_of_week`, so use `isodow`, which returns the same numbers.

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

Returns the ISO 8601 year that `ts` belongs to. ISO weeks start on Monday, and week 1 of a year is the week that contains the first Thursday of that year. Because of this, the first days of January can belong to the last week of the previous ISO year. The last days of December can belong to week 1 of the next ISO year. For other dates, the result equals `year({{ts}})`.

If `ts` is `NULL`, the result is `NULL`. To get the ISO week number that goes with this year, use the [`week` function](#athena-duckdb-functions-date-time-week).

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

```sql
isoyear({{ts}})
```

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

The `isoyear` function takes the following argument:

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

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

`BIGINT`

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

The following SQL query returns the ISO 8601 year of a timestamp in August.

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

The query returns the following result.


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

The following SQL query shows that January 1, 2021, a Friday, belongs to week 53 of ISO year 2020.

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

The query returns the following result.


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

The following SQL query shows that December 30, 2024, a Monday, belongs to week 1 of ISO year 2025.

```sql
SELECT
    isoyear(DATE '2024-12-30') AS iso_year,
    year(DATE '2024-12-30') AS calendar_year,
    week(DATE '2024-12-30') AS iso_week
```

The query returns the following result.


| iso\_year | calendar\_year | iso\_week | 
| --- | --- | --- | 
| `2025` | `2024` | `1` | 

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

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

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

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

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

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

Returns the week of the year of `ts`, from 1 to 53, as ISO 8601 defines it. ISO weeks start on Monday, and week 1 is the week that contains the first Thursday of the year. If `ts` is `NULL`, the result is `NULL`.

Because of this rule, the first days of January can be in week 52 or 53 of the year before. The last days of December can be in week 1 of the year after. To get the year that an ISO week belongs to, use the [`isoyear` function](#athena-duckdb-functions-date-time-isoyear). To get the year and the week as one number, use the [`yearweek` function](#athena-duckdb-functions-date-time-yearweek). The `weekofyear` function returns the same result as `week`.

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

```sql
week({{ts}})
```

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

The `week` function takes the following argument:

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

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

`BIGINT`

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

The following SQL query returns the ISO week number of a timestamp.

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

The query returns the following result.


| result | 
| --- | 
| `31` | 

The following SQL query returns the week of January 1, 2021. That day is a Friday, so it is in the last ISO week of 2020.

```sql
SELECT week(DATE '2021-01-01') AS result
```

The query returns the following result.


| result | 
| --- | 
| `53` | 

The following SQL query returns the week of December 30, 2024. That day is a Monday in the first ISO week of 2025.

```sql
SELECT week(DATE '2024-12-30') AS result
```

The query returns the following result.


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

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

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

You cannot pass an `INTERVAL` value. The call fails.

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

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

Returns `isoyear({{ts}}) * 100 + week({{ts}})`, so August 3, 2021 gives `202131`. Both parts follow ISO 8601: weeks start on Monday, and the year is the year that the week belongs to. That year can differ from the calendar year in the first and last days of a year. If `ts` is `NULL`, the result is `NULL`.

Because the week always fills the last two digits, the results sort in time order. Use `yearweek` to group and sort rows by ISO week.

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

```sql
yearweek({{ts}})
```

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

The `yearweek` function takes the following argument:

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

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

`BIGINT`

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

The following SQL query returns the ISO year and week of a timestamp.

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

The query returns the following result.


| result | 
| --- | 
| `202131` | 

The following SQL query returns the year and week of January 1, 2021. The ISO year is 2020, not 2021.

```sql
SELECT yearweek(DATE '2021-01-01') AS result
```

The query returns the following result.


| result | 
| --- | 
| `202053` | 

The following SQL query returns the year and week of December 30, 2024, which is in the first ISO week of 2025.

```sql
SELECT yearweek(DATE '2024-12-30') AS result
```

The query returns the following result.


| result | 
| --- | 
| `202501` | 

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

To split the result, use `yearweek({{ts}}) // 100` for the year and `yearweek({{ts}}) % 100` for the week.

Pass a date or timestamp, not a string. A call such as `yearweek('2021-08-03')` fails. You also cannot pass an `INTERVAL` value.

For a `TIMESTAMP WITH TIME ZONE` value, the year and week are computed in the session time zone, which is UTC.