

# Current date and time functions

Use these functions to get the date or time at which the current query started, in UTC, or that time minus an interval. Every call in a query returns the same value, and the value changes from one query to the next.

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

Returns the date and time that is `interval` before the time at which the current query started, as a `TIMESTAMP WITH TIME ZONE` in UTC. The expression `ago({{interval}})` returns the same value as `now() - {{interval}}`, so the result varies with the time at which you run the query. If `interval` is `NULL`, the result is `NULL`.

Use `ago` to keep recent rows, as in `WHERE {{order_ts}} >= ago(INTERVAL 7 DAY)`.

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

```sql
ago({{interval}})
```

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

The `ago` function takes the following argument:

**{{interval}}**  
The length of time to go back, as an `INTERVAL`, or a `VARCHAR` value that can be cast to an interval, such as `'1 day'`.

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

`TIMESTAMP WITH TIME ZONE`

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

The following SQL query shows that the result is earlier than the current time. The result varies from run to run, so the query compares it instead of showing it.

```sql
SELECT ago(INTERVAL 1 DAY) < now() AS is_earlier
```

The query returns the following result.


| is\_earlier | 
| --- | 
| `true` | 

The following SQL query shows that the result is exactly the interval before the current time.

```sql
SELECT
    now() - ago(
        INTERVAL '2 hours'
    ) = INTERVAL '2 hours' AS is_two_hours
```

The query returns the following result.


| is\_two\_hours | 
| --- | 
| `true` | 

The following SQL query counts the rows from the last 7 days. Only the row with the current time is recent.

```sql
SELECT count(*) AS recent_rows
FROM (VALUES
    (now()),
    (TIMESTAMPTZ '2000-01-01 00:00:00+00')
) AS t(ts)
WHERE ts >= ago(INTERVAL 7 DAY)
```

The query returns the following result.


| recent\_rows | 
| --- | 
| `1` | 

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

Returns the date on which the current query started, in the session time zone, UTC. The value is the same for every row and every call in a query, and it varies with the date on which the query runs.

You can write `current_date` with or without parentheses.

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

```sql
current_date
current_date()
```

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

`DATE`

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

The following SQL query shows that `current_date` is the UTC date of the current time. The date varies from day to day, so the query compares it instead of showing it.

```sql
SELECT current_date = CAST(now() AS DATE) AS is_today
```

The query returns the following result.


| is\_today | 
| --- | 
| `true` | 

The following SQL query counts the rows whose date is in the last 7 days. Subtracting an integer from a `DATE` subtracts that many days.

```sql
SELECT count(*) AS recent_rows
FROM (VALUES
    (current_date),
    (DATE '2000-01-01')
) AS t(d)
WHERE d >= current_date - 7
```

The query returns the following result.


| recent\_rows | 
| --- | 
| `1` | 

The following SQL query shows that the forms with and without parentheses return the same value.

```sql
SELECT current_date() = current_date AS same_value
```

The query returns the following result.


| same\_value | 
| --- | 
| `true` | 

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

Because the session time zone is always UTC, `current_date` can be a day earlier or later than the date in your own time zone.

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

Returns the time of day at which the current query started, in the session time zone, UTC, as a `TIME` value without a time zone. The value is the same for every row and every call in a query, and it varies with the time at which the query runs.

`localtime`, written without parentheses, returns the same value.

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

```sql
current_localtime()
localtime
```

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

`TIME`

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

The following SQL query shows that `current_localtime` is the time-of-day part of `current_localtimestamp`. The time varies from run to run, so the query compares it instead of showing it.

```sql
SELECT
    current_localtime() = CAST(
        current_localtimestamp() AS TIME
    ) AS same_time
```

The query returns the following result.


| same\_time | 
| --- | 
| `true` | 

The following SQL query shows that `localtime` returns the same value.

```sql
SELECT localtime = current_localtime() AS same_value
```

The query returns the following result.


| same\_value | 
| --- | 
| `true` | 

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

Returns the date and time at which the current query started, in the session time zone, UTC, as a `TIMESTAMP` value without a time zone. The value is the same for every row and every call in a query, and it varies with the time at which the query runs.

`localtimestamp`, written without parentheses, returns the same value. To get the same instant as a `TIMESTAMP WITH TIME ZONE`, use `now()`.

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

```sql
current_localtimestamp()
localtimestamp
```

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

`TIMESTAMP`

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

The following SQL query shows that `current_localtimestamp` is the current time in UTC without the time zone. The time varies from run to run, so the query compares it instead of showing it.

```sql
SELECT
    current_localtimestamp() = CAST(
        now() AS TIMESTAMP
    ) AS is_utc_now
```

The query returns the following result.


| is\_utc\_now | 
| --- | 
| `true` | 

The following SQL query shows that `localtimestamp` returns the same value.

```sql
SELECT
    localtimestamp = current_localtimestamp() AS same_value
```

The query returns the following result.


| same\_value | 
| --- | 
| `true` | 

The following SQL query shows that the date part of the result is `current_date`.

```sql
SELECT
    CAST(
        current_localtimestamp() AS DATE
    ) = current_date AS same_day
```

The query returns the following result.


| same\_day | 
| --- | 
| `true` | 

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

Returns the current time of day as a `TIME WITH TIME ZONE` value, in the session time zone, which is UTC. The value does not change while a query runs, so every call in the same query returns the same value. The result varies from query to query.

The result equals the time part of `get_current_timestamp()`. The SQL keyword `current_time` returns the same value. To get the current time without a time zone, use the [`current_localtime` function](#athena-duckdb-functions-date-time-current-localtime).

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

```sql
get_current_time()
```

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

`TIME WITH TIME ZONE`

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

The following SQL query returns the data type of the result. The time itself varies with each query, so the query does not show it.

```sql
SELECT typeof(get_current_time()) AS result
```

The query returns the following result.


| result | 
| --- | 
| `TIME WITH TIME ZONE` | 

The following SQL query checks that the result equals the time part of the current timestamp.

```sql
SELECT
    get_current_time() = CAST(
        get_current_timestamp() AS TIME WITH TIME ZONE
    ) AS is_same
```

The query returns the following result.


| is\_same | 
| --- | 
| `true` | 

The following SQL query checks that the `current_time` keyword returns the same value.

```sql
SELECT current_time = get_current_time() AS is_same
```

The query returns the following result.


| is\_same | 
| --- | 
| `true` | 

The following SQL query checks that the time is in UTC.

```sql
SELECT
    CAST(
        get_current_time() AS VARCHAR
    ) LIKE '%+00' AS is_utc
```

The query returns the following result.


| is\_utc | 
| --- | 
| `true` | 

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

Because the session time zone is UTC, a cast of the result to `VARCHAR` ends with the offset `+00`.

## `get_current_timestamp` function
<a name="athena-duckdb-functions-date-time-get-current-timestamp"></a>

Returns the current date and time as a `TIMESTAMP WITH TIME ZONE` value with microsecond precision, in the session time zone, which is UTC. The value does not change while a query runs, so every call in the same query returns the same value. The result varies from query to query.

`now` and `transaction_timestamp` are aliases of `get_current_timestamp`, and the SQL keyword `current_timestamp` returns the same value. To get the current date and time without a time zone, use the [`current_localtimestamp` function](#athena-duckdb-functions-date-time-current-localtimestamp). To get only the date, use the [`current_date` function](#athena-duckdb-functions-date-time-current-date).

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

```sql
get_current_timestamp()
now()
transaction_timestamp()
```

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

`TIMESTAMP WITH TIME ZONE`

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

The following SQL query returns the data type of the result. The timestamp itself varies with each query, so the query does not show it.

```sql
SELECT typeof(get_current_timestamp()) AS result
```

The query returns the following result.


| result | 
| --- | 
| `TIMESTAMP WITH TIME ZONE` | 

The following SQL query checks that `get_current_timestamp` and its aliases return the same value in one query.

```sql
SELECT
    get_current_timestamp() = now()
        AND now() = transaction_timestamp() AS is_same
```

The query returns the following result.


| is\_same | 
| --- | 
| `true` | 

The following SQL query checks that the `current_timestamp` keyword returns the same value as `now`.

```sql
SELECT current_timestamp = now() AS is_same
```

The query returns the following result.


| is\_same | 
| --- | 
| `true` | 

The following SQL query checks that the timestamp is in UTC.

```sql
SELECT CAST(now() AS VARCHAR) LIKE '%+00' AS is_utc
```

The query returns the following result.


| is\_utc | 
| --- | 
| `true` | 

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

Because the session time zone is UTC, a cast of the result to `VARCHAR` ends with the offset `+00`.

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

In Athena engine version 3, `now()` and `current_timestamp` return a `timestamp(3) with time zone` value, which has millisecond precision. In DuckDB, the value has microsecond precision.

In Athena engine version 3, a cast of `now()` to `VARCHAR` ends with the time zone name `UTC`. In DuckDB, it ends with the offset `+00`.

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

Returns the current date as a `DATE` value, in the session time zone, which is UTC. The value does not change while a query runs, so every row of a query gets the same date. The result is the same as `current_date`.

The result varies with the date on which the query runs, so the examples show properties of the result instead of a date.

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

```sql
today()
```

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

`DATE`

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

The following SQL query checks that `today` returns the same date as `current_date`.

```sql
SELECT today() = current_date AS is_current_date
```

The query returns the following result.


| is\_current\_date | 
| --- | 
| `true` | 

The following SQL query uses `typeof` to show that `today` returns a `DATE` value.

```sql
SELECT typeof(today()) AS result
```

The query returns the following result.


| result | 
| --- | 
| `DATE` | 

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

`today` uses UTC, not your local time zone. Near midnight, the result can be one day ahead of or behind the date where you are. To get the date in another time zone, convert the current timestamp first, for example `CAST(timezone('America/New_York', now()) AS DATE)`.