Functions for working with dates and times

**Returned value**

Returns a `Date32` value constructed from the provided arguments [`Date32`](/docs/sql-reference/data-types/date32)

**Examples**

**Date32 from a year, month, day**

```
SELECT makeDate(2023, 2, 28) AS date;
```

```
┌───────date─┐
│ 2023-02-28 │
└────────────┘
```

**Date32 from year and day of year**

```
SELECT makeDate(2023, 42) AS date;
```

```
┌───────date─┐
│ 2023-02-11 │
└────────────┘
```

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

Introduced in: v22.6.0

Creates a `DateTime` from year, month, day, hour, minute, and second, with optional timezone.

**Syntax**

```
makeDateTime(year, month, day, hour, minute, second[, timezone])
```

**Arguments**

- `year` — Year number. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Decimal`](/docs/sql-reference/data-types/decimal)
- `month` — Month number (1-12). [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Decimal`](/docs/sql-reference/data-types/decimal)
- `day` — Day of the month (1-31). [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Decimal`](/docs/sql-reference/data-types/decimal)
- `hour` — Hour (0-23). [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Decimal`](/docs/sql-reference/data-types/decimal)
- `minute` — Minute (0-59). [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Decimal`](/docs/sql-reference/data-types/decimal)
- `second` — Second (0-59). [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Decimal`](/docs/sql-reference/data-types/decimal)
- `timezone` — Timezone name. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns a `DateTime` value constructed from the provided arguments [`DateTime`](/docs/sql-reference/data-types/datetime)

**Examples**

**DateTime from year, month, day, hour, minute, second**

```
SELECT makeDateTime(2023, 2, 28, 17, 12, 33) AS DateTime;
```

```
┌────────────DateTime─┐
│ 2023-02-28 17:12:33 │
└─────────────────────┘
```

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

Introduced in: v22.6.0

Creates a `DateTime64` from year, month, day, hour, minute, second, with optional fraction, precision, and timezone.

**Syntax**

```
makeDateTime64(year, month, day, hour, minute, second[, fraction[, precision[, timezone]]])
```

**Arguments**

- `year` — Year number. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Decimal`](/docs/sql-reference/data-types/decimal)
- `month` — Month number (1-12). [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Decimal`](/docs/sql-reference/data-types/decimal)
- `day` — Day of the month (1-31). [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Decimal`](/docs/sql-reference/data-types/decimal)
- `hour` — Hour (0-23). [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Decimal`](/docs/sql-reference/data-types/decimal)
- `minute` — Minute (0-59). [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Decimal`](/docs/sql-reference/data-types/decimal)
- `second` — Second (0-59). [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Decimal`](/docs/sql-reference/data-types/decimal)
- `fraction` — Fractional part of the second. [`(U)Int*`](/docs/sql-reference/data-types/int-uint) or [`Float*`](/docs/sql-reference/data-types/float) or [`Decimal`](/docs/sql-reference/data-types/decimal)
- `precision` — Precision for the fractional part (0-9). [`UInt8`](/docs/sql-reference/data-types/int-uint)
- `timezone` — Timezone name. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns a `DateTime64` value constructed from the provided arguments [`DateTime64`](/docs/sql-reference/data-types/datetime64)

**Examples**

**DateTime64 from year, month, day, hour, minute, second**

```
SELECT makeDateTime64(2023, 5, 15, 10, 30, 45, 779, 5);
```

```
┌─makeDateTime64(2023, 5, 15, 10, 30, 45, 779, 5)─┐
│                       2023-05-15 10:30:45.00779 │
└─────────────────────────────────────────────────┘
```

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

Introduced in: v22.1.0

Returns the name of the month as a string from a date or date with time value.

**Syntax**

```
monthName(datetime)
```

**Arguments**

- `datetime` — Date or date with time. [`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)

**Returned value**

Returns the name of the month. [`String`](/docs/sql-reference/data-types/string)

**Examples**

**Get month name from date**

```
WITH toDateTime('2021-04-14 11:22:33') AS date_value
SELECT monthName(date_value)
```

```
┌─monthName(date_value)─┐
│ April                 │
└───────────────────────┘
```

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

Introduced in: v1.1.0

Returns the current date and time at the moment of query analysis. The function is a constant expression.

**Syntax**

```
now([timezone])
```

**Aliases**: `current_timestamp`

**Arguments**

- `timezone` — Optional. Timezone name for the returned value. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns the current date and time. [`DateTime`](/docs/sql-reference/data-types/datetime)

**Examples**

**Query without timezone**

```
SELECT now()
```

```
┌───────────────now()─┐
│ 2020-10-17 07:42:09 │
└─────────────────────┘
```

**Query with specified timezone**

```
SELECT now('Asia/Istanbul')
```

```
┌─now('Asia/Istanbul')─┐
│  2020-10-17 10:42:23 │
└──────────────────────┘
```

**SQL standard syntax without parentheses**

```
SELECT NOW, CURRENT_TIMESTAMP
```

```
┌─────────────────NOW─┬───CURRENT_TIMESTAMP─┐
│ 2020-10-17 07:42:19 │ 2020-10-17 07:42:19 │
└─────────────────────┴─────────────────────┘
```

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

Introduced in: v20.1.0

Returns the current date and time with sub-second precision at the moment of query analysis. The function is a constant expression.

**Syntax**

```
now64([scale[, timezone]])
```

**Arguments**

- `scale` — Optional. Tick size (precision): 10^-precision seconds. Valid range: [0 : 9]. Typically, are used - 3 (default) (milliseconds), 6 (microseconds), 9 (nanoseconds). [`UInt8`](/docs/sql-reference/data-types/int-uint)
- `timezone` — Optional. Timezone name for the returned value. [`String`](/docs/sql-reference/data-types/string)

**Returned value**

Returns current date and time with sub-second precision. [`DateTime64`](/docs/sql-reference/data-types/datetime64)

**Examples**

**Query with default and custom precision**

```
SELECT now64(), now64(9, 'Asia/Istanbul')
```

```
┌─────────────────now64()─┬─────now64(9, 'Asia/Istanbul')─┐
│ 2022-08-21 19:34:26.196 │ 2022-08-21 22:34:26.196542766 │
└─────────────────────────┴───────────────────────────────┘
```

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

Introduced in: v22.8.0

Returns the current date and time at the moment of processing of each block of data. In contrast to the function [`now`](#now), it is not a constant expression, and the returned value will be different in different blocks for long-running queries.

It makes sense to use this function to generate the current time in long-running `INSERT SELECT` queries.

**Syntax**

```
nowInBlock([timezone])
```

**Arguments**

- `timezone` — Optional. Timezone name for the returned value. [`String`](/docs/sql-reference/data-types/string)

**Returned value**