

# Date and time construction functions

Use these functions to build a date, a time, or a timestamp from its parts, such as the year, the month, and the day. To build a `TIMESTAMP WITH TIME ZONE` value, you can also name the time zone that the parts are in.

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

Combines `year`, `month`, and `day` into one `DATE` value. You can also pass the three parts as one `STRUCT` with the fields `year`, `month`, and `day`, or pass a single `INTEGER` that is the number of days since 1970-01-01. A negative number of days gives a date before 1970-01-01.

If any part is `NULL`, the result is `NULL`.

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

```sql
make_date({{year}}, {{month}}, {{day}})
make_date({{date_struct}})
make_date({{days}})
```

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

The `make_date` function takes the following arguments:

**{{year}}**  
The year of the result, as a `BIGINT` value.

**{{month}}**  
The month, as a `BIGINT` value from `1` to `12`.

**{{day}}**  
The day of the month, as a `BIGINT` value from `1` to the number of days in that month.

**{{date\_struct}}**  
The date parts, as a `STRUCT` with the `BIGINT` fields `year`, `month`, and `day`. All three fields are required.

**{{days}}**  
The number of days since 1970-01-01, as an `INTEGER` value.

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

`DATE`

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

The following SQL query builds a date from a year, month, and day.

```sql
SELECT make_date(1992, 9, 20) AS result
```

The query returns the following result.


| result | 
| --- | 
| `1992-09-20` | 

The following SQL query builds a date from a `STRUCT` of the three parts.

```sql
SELECT
    make_date(
        {'year': 2024, 'month': 11, 'day': 14}
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `2024-11-14` | 

The following SQL query returns the date that is 19,000 days after 1970-01-01.

```sql
SELECT make_date(19000) AS result
```

The query returns the following result.


| result | 
| --- | 
| `2022-01-08` | 

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

If the parts do not form a valid date, such as February 30 or a month of `13`, the query fails instead of returning `NULL`.

The one-argument form takes an `INTEGER`, not a `BIGINT`. A `BIGINT` value, such as the result of subtracting one `DATE` from another, makes the query fail, so cast it first, as in `make_date(CAST({{days}} AS INTEGER))`.

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

Combines `hour`, `minute`, and `seconds` into one `TIME` value. `seconds` can have a fractional part, which is kept to the microsecond.

If any part is `NULL`, the result is `NULL`. To build a date and a time together, use the [`make_timestamp` function](#athena-duckdb-functions-date-time-make-timestamp).

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

```sql
make_time({{hour}}, {{minute}}, {{seconds}})
```

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

The `make_time` function takes the following arguments:

**{{hour}}**  
The hour, as a `BIGINT` value from `0` to `23`.

**{{minute}}**  
The minute, as a `BIGINT` value from `0` to `59`.

**{{seconds}}**  
The seconds, as a `DOUBLE` value from `0` to `60`. It can have a fractional part.

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

`TIME`

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

The following SQL query builds a time with fractional seconds.

```sql
SELECT make_time(13, 34, 27.123456) AS result
```

The query returns the following result.


| result | 
| --- | 
| `13:34:27.123456` | 

The following SQL query builds a time with whole seconds.

```sql
SELECT make_time(9, 5, 30) AS result
```

The query returns the following result.


| result | 
| --- | 
| `09:05:30` | 

The following SQL query shows that a `NULL` part gives a `NULL` result.

```sql
SELECT make_time(9, 5, NULL) IS NULL AS is_null
```

The query returns the following result.


| is\_null | 
| --- | 
| `true` | 

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

If a part is out of range, such as an hour of `25` or a minute of `61`, the query fails instead of returning `NULL`.

`seconds` is rounded to the nearest microsecond, and the rounding can carry into the minute. For example, `make_time(9, 5, 59.9999999)` returns `09:06:00`. A `seconds` value of exactly `60` also carries into the next minute, so `make_time(10, 0, 60)` returns `10:01:00`.

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

Combines `year`, `month`, `day`, `hour`, `minute`, and `seconds` into one `TIMESTAMP` value. `seconds` can have a fractional part, which is kept to the microsecond.

With one argument, returns the `TIMESTAMP` that is `microseconds` microseconds after 1970-01-01 00:00:00. For a number of milliseconds, use the [`make_timestamp_ms` function](duckdb-functions-date-time-epoch-conversion.md#athena-duckdb-functions-date-time-make-timestamp-ms), and for nanoseconds, use the [`make_timestamp_ns` function](duckdb-functions-date-time-epoch-conversion.md#athena-duckdb-functions-date-time-make-timestamp-ns).

If any argument is `NULL`, the result is `NULL`. The result has no time zone. To build a `TIMESTAMP WITH TIME ZONE` value, use the [`make_timestamptz` function](#athena-duckdb-functions-date-time-make-timestamptz).

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

```sql
make_timestamp({{year}}, {{month}}, {{day}}, {{hour}}, {{minute}}, {{seconds}})
make_timestamp({{microseconds}})
```

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

The `make_timestamp` function takes the following arguments:

**{{year}}**  
The year of the result, as a `BIGINT` value.

**{{month}}**  
The month, as a `BIGINT` value from `1` to `12`.

**{{day}}**  
The day of the month, as a `BIGINT` value.

**{{hour}}**  
The hour, as a `BIGINT` value from `0` to `23`.

**{{minute}}**  
The minute, as a `BIGINT` value from `0` to `59`.

**{{seconds}}**  
The seconds, as a `DOUBLE` value. It can have a fractional part.

**{{microseconds}}**  
The number of microseconds since 1970-01-01 00:00:00, as a `BIGINT` value.

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

`TIMESTAMP`

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

The following SQL query builds a timestamp from its parts.

```sql
SELECT
    make_timestamp(
        1992, 9, 20, 13, 34, 27.123456
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `1992-09-20 13:34:27.123456` | 

The following SQL query builds a timestamp from a number of microseconds since 1970-01-01 00:00:00.

```sql
SELECT make_timestamp(1667810584123456) AS result
```

The query returns the following result.


| result | 
| --- | 
| `2022-11-07 08:43:04.123456` | 

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

If the parts do not form a valid date and time, such as February 30 or a minute of `60`, the query fails instead of returning `NULL`.

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

Combines `year`, `month`, `day`, `hour`, `minute`, and `seconds` into one `TIMESTAMP WITH TIME ZONE` value. The parts are read as local time in `timezone`. Without `timezone`, they are read in the session time zone, which is UTC. The result is shown in UTC, so a value built in another time zone shows the matching UTC time.

With one argument, returns the `TIMESTAMP WITH TIME ZONE` value that is `microseconds` microseconds after 1970-01-01 00:00:00 UTC.

If any argument is `NULL`, the result is `NULL`. To build a value with no time zone, use the [`make_timestamp` function](#athena-duckdb-functions-date-time-make-timestamp).

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

```sql
make_timestamptz({{year}}, {{month}}, {{day}}, {{hour}}, {{minute}}, {{seconds}}
    [, {{timezone}} ])
make_timestamptz({{microseconds}})
```

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

The `make_timestamptz` function takes the following arguments:

**{{year}}**  
The year of the result, as a `BIGINT` value.

**{{month}}**  
The month, as a `BIGINT` value from `1` to `12`.

**{{day}}**  
The day of the month, as a `BIGINT` value.

**{{hour}}**  
The hour, as a `BIGINT` value from `0` to `23`.

**{{minute}}**  
The minute, as a `BIGINT` value from `0` to `59`.

**{{seconds}}**  
The seconds, as a `DOUBLE` value. It can have a fractional part.

**{{timezone}}**  
The name of the time zone of the parts, as a `VARCHAR` value, such as `'America/New_York'`. The default is the session time zone, UTC. This argument is optional.

**{{microseconds}}**  
The number of microseconds since 1970-01-01 00:00:00 UTC, as a `BIGINT` value.

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

`TIMESTAMP WITH TIME ZONE` (`TIMESTAMPTZ`)

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

The following SQL query builds a timestamp with time zone from its parts. With no `timezone`, the parts are read as UTC.

```sql
SELECT
    make_timestamptz(
        1992, 9, 20, 13, 34, 27.123456
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `1992-09-20 13:34:27.123456+00` | 

The following SQL query reads the same parts as local time in New York. The result shows the matching time in UTC, four hours later.

```sql
SELECT
    make_timestamptz(
        1992, 9, 20, 13, 34, 27.123456,
        'America/New_York'
    ) AS result
```

The query returns the following result.


| result | 
| --- | 
| `1992-09-20 17:34:27.123456+00` | 

The following SQL query builds a timestamp with time zone from a number of microseconds since 1970-01-01 00:00:00 UTC.

```sql
SELECT make_timestamptz(1667810584123456) AS result
```

The query returns the following result.


| result | 
| --- | 
| `2022-11-07 08:43:04.123456+00` | 

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

`timezone` must be a time zone name, such as `'America/New_York'`, or an abbreviation such as `'EST'`. An offset string such as `'+05:00'` is not a time zone name, and the query fails. To list the names that you can use, query `pg_timezone_names()`.

Parts that are out of range, such as February 30, a month of `13`, or a minute of `60`, do not make the query fail. Each one carries into the next larger part instead. For example, `make_timestamptz(1992, 2, 30, 13, 34, 27.123456)` returns `1992-03-01 13:34:27.123456+00`, `make_timestamptz(1992, 13, 1, 0, 0, 0)` returns `1993-01-01 00:00:00+00`, and `make_timestamptz(1992, 9, 20, 13, 60, 0)` returns `1992-09-20 14:00:00+00`. This differs from `make_timestamp`, which fails for a minute of `60`.