Functions for working with dates and times

## addDays[​](#addDays "Direct link to addDays")

Introduced in: v1.1.0

Adds a specified number of days to a date, a date with time or a string-encoded date or date with time.

**Syntax**

```
addDays(datetime, num)
```

**Arguments**

- `datetime` — Date or date with time to add specified number of days to. [`Date`](/docs/sql-reference/data-types/date) or [`Date32`](/docs/sql-reference/data-types/date32) or [`DateTime`](/docs/sql-reference/data-types/datetime) or [`DateTime64`](/docs/sql-reference/data-types/datetime64) or [`String`](/docs/sql-reference/data-types/string)
- `num` — Number of days to add. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float)

**Returned value**

Returns `datetime` plus `num` days. [`Date`](/docs/sql-reference/data-types/date) or [`Date32`](/docs/sql-reference/data-types/date32) or [`DateTime`](/docs/sql-reference/data-types/datetime) or [`DateTime64`](/docs/sql-reference/data-types/datetime64)

**Examples**

**Add days to different date types**

```
WITH
    toDate('2024-01-01') AS date,
    toDateTime('2024-01-01 00:00:00') AS date_time,
    '2024-01-01 00:00:00' AS date_time_string
SELECT
    addDays(date, 5) AS add_days_with_date,
    addDays(date_time, 5) AS add_days_with_date_time,
    addDays(date_time_string, 5) AS add_days_with_date_time_string
```

```
┌─add_days_with_date─┬─add_days_with_date_time─┬─add_days_with_date_time_string─┐
│         2024-01-06 │     2024-01-06 00:00:00 │        2024-01-06 00:00:00.000 │
└────────────────────┴─────────────────────────┴────────────────────────────────┘
```

**Using alternative INTERVAL syntax**

```
SELECT dateAdd('1998-06-16'::Date, INTERVAL 10 day)
```

```
┌─plus(CAST('1⋯valDay(10))─┐
│               1998-06-26 │
└──────────────────────────┘
```

## addHours[​](#addHours "Direct link to addHours")

Introduced in: v1.1.0

Adds a specified number of hours to a date, a date with time or a string-encoded date or date with time.

**Syntax**

```
addHours(datetime, num)
```

**Arguments**

- `datetime` — Date or date with time to add specified number of hours to. [`Date`](/docs/sql-reference/data-types/date) or [`Date32`](/docs/sql-reference/data-types/date32) or [`DateTime`](/docs/sql-reference/data-types/datetime) or [`DateTime64`](/docs/sql-reference/data-types/datetime64) or [`String`](/docs/sql-reference/data-types/string)
- `num` — Number of hours to add. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float)

**Returned value**

Returns `datetime` plus `num` hours [`DateTime`](/docs/sql-reference/data-types/datetime) or [`DateTime64(3)`](/docs/sql-reference/data-types/datetime64)

**Examples**

**Add hours to different date types**

```
WITH
    toDate('2024-01-01') AS date,
    toDateTime('2024-01-01 00:00:00') AS date_time,
    '2024-01-01 00:00:00' AS date_time_string
SELECT
    addHours(date, 12) AS add_hours_with_date,
    addHours(date_time, 12) AS add_hours_with_date_time,
    addHours(date_time_string, 12) AS add_hours_with_date_time_string
```

```
┌─add_hours_with_date─┬─add_hours_with_date_time─┬─add_hours_with_date_time_string─┐
│ 2024-01-01 12:00:00 │      2024-01-01 12:00:00 │         2024-01-01 12:00:00.000 │
└─────────────────────┴──────────────────────────┴─────────────────────────────────┘
```

**Using alternative INTERVAL syntax**

```
SELECT dateAdd('1998-06-16'::Date, INTERVAL 10 hour)
```

```
┌─plus(CAST('1⋯alHour(10))─┐
│      1998-06-16 10:00:00 │
└──────────────────────────┘
```

## addInterval[​](#addInterval "Direct link to addInterval")

Introduced in: v22.11.0

Adds an interval to another interval or tuple of intervals.

Note

Intervals of the same type will be combined into a single interval. For instance if `toIntervalDay(1)` and `toIntervalDay(2)` are passed then the result will be `(3)` rather than `(1,1)`.

**Syntax**

```
addInterval(interval_1, interval_2)
```

**Arguments**

- `interval_1` — First interval or tuple of intervals. [`Interval`](/docs/sql-reference/data-types/int-uint) or [`Tuple(Interval)`](/docs/sql-reference/data-types/tuple)
- `interval_2` — Second interval to be added. [`Interval`](/docs/sql-reference/data-types/int-uint)

**Returned value**

Returns a tuple of intervals [`Tuple(Interval)`](/docs/sql-reference/data-types/tuple)

**Examples**

**Add intervals**

```
SELECT addInterval(INTERVAL 1 DAY, INTERVAL 1 MONTH);
SELECT addInterval((INTERVAL 1 DAY, INTERVAL 1 YEAR), INTERVAL 1 MONTH);
SELECT addInterval(INTERVAL 2 DAY, INTERVAL 1 DAY)
```

```
┌─addInterval(toIntervalDay(1), toIntervalMonth(1))─┐
│ (1,1)                                             │
└───────────────────────────────────────────────────┘
┌─addInterval((toIntervalDay(1), toIntervalYear(1)), toIntervalMonth(1))─┐
│ (1,1,1)                                                                │
└────────────────────────────────────────────────────────────────────────┘
┌─addInterval(toIntervalDay(2), toIntervalDay(1))─┐
│ (3)                                             │
└─────────────────────────────────────────────────┘
```

## addMicroseconds[​](#addMicroseconds "Direct link to addMicroseconds")

Introduced in: v22.6.0

Adds a specified number of microseconds to a date with time or a string-encoded date with time.

**Syntax**

```
addMicroseconds(datetime, num)
```

**Arguments**

- `datetime` — Date with time to add specified number of microseconds to. [`DateTime`](/docs/sql-reference/data-types/datetime) or [`DateTime64`](/docs/sql-reference/data-types/datetime64) or [`String`](/docs/sql-reference/data-types/string)
- `num` — Number of microseconds to add. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float)

**Returned value**

Returns `date_time` plus `num` microseconds [`DateTime64`](/docs/sql-reference/data-types/datetime64)

**Examples**

**Add microseconds to different date time types**

```
WITH
    toDateTime('2024-01-01 00:00:00') AS date_time,
    '2024-01-01 00:00:00' AS date_time_string
SELECT
    addMicroseconds(date_time, 1000000) AS add_microseconds_with_date_time,
    addMicroseconds(date_time_string, 1000000) AS add_microseconds_with_date_time_string
```

```
┌─add_microseconds_with_date_time─┬─add_microseconds_with_date_time_string─┐
│      2024-01-01 00:00:01.000000 │             2024-01-01 00:00:01.000000 │
└─────────────────────────────────┴────────────────────────────────────────┘
```

**Using alternative INTERVAL syntax**

```
SELECT dateAdd('1998-06-16'::DateTime, INTERVAL 10 microsecond)
```

```
┌─plus(CAST('19⋯osecond(10))─┐
│ 1998-06-16 00:00:00.000010 │
└────────────────────────────┘
```

## addMilliseconds[​](#addMilliseconds "Direct link to addMilliseconds")

Introduced in: v22.6.0

Adds a specified number of milliseconds to a date with time or a string-encoded date with time.

**Syntax**

```
addMilliseconds(datetime, num)
```

**Arguments**

- `datetime` — Date with time to add specified number of milliseconds to. [`DateTime`](/docs/sql-reference/data-types/datetime) or [`DateTime64`](/docs/sql-reference/data-types/datetime64) or [`String`](/docs/sql-reference/data-types/string)
- `num` — Number of milliseconds to add. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float)

**Returned value**

Returns `datetime` plus `num` milliseconds [`DateTime64`](/docs/sql-reference/data-types/datetime64)

**Examples**

**Add milliseconds to different date time types**

```
WITH
    toDateTime('2024-01-01 00:00:00') AS date_time,
    '2024-01-01 00:00:00' AS date_time_string
SELECT
    addMilliseconds(date_time, 1000) AS add_milliseconds_with_date_time,
    addMilliseconds(date_time_string, 1000) AS add_milliseconds_with_date_time_string
```

```
┌─add_milliseconds_with_date_time─┬─add_milliseconds_with_date_time_string─┐
│         2024-01-01 00:00:01.000 │                2024-01-01 00:00:01.000 │
└─────────────────────────────────┴────────────────────────────────────────┘
```

**Using alternative INTERVAL syntax**

```
SELECT dateAdd('1998-06-16'::DateTime, INTERVAL 10 millisecond)
```