Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOCSUP-2018-formatDateTime_description_update: added two modificators into the table of supported modificators #15614

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 32 additions & 4 deletions docs/en/sql-reference/functions/date-time-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -486,20 +486,32 @@ For a time interval starting at ‘StartTime’ and continuing for ‘Duration
For example, `timeSlots(toDateTime('2012-01-01 12:20:00'), 600) = [toDateTime('2012-01-01 12:00:00'), toDateTime('2012-01-01 12:30:00')]`.
This is necessary for searching for pageviews in the corresponding session.

## formatDateTime(Time, Format\[, Timezone\]) {#formatdatetime}
## formatDateTime {#formatdatetime}

Function formats a Time according given Format string. N.B.: Format is a constant expression, e.g. you can not have multiple formats for single result column.

Supported modifiers for Format:
(“Example” column shows formatting result for time `2018-01-02 22:33:44`)
**Syntax**

``` sql
formatDateTime(Time, Format\[, Timezone\])
```

**Returned value(s)**

| Modifier | Description | Example |
Returnes time and date values according to the determined format.

**Replacement fields**
Using replacement fields, you can define a pattern for the resulting string. “Example” column shows formatting result for `2018-01-02 22:33:44`.

| Placeholder | Description | Example |
|----------|---------------------------------------------------------|------------|
| %C | year divided by 100 and truncated to integer (00-99) | 20 |
| %d | day of the month, zero-padded (01-31) | 02 |
| %D | Short MM/DD/YY date, equivalent to %m/%d/%y | 01/02/18 |
| %e | day of the month, space-padded ( 1-31) | 2 |
| %F | short YYYY-MM-DD date, equivalent to %Y-%m-%d | 2018-01-02 |
| %G | four-digit year format for ISO week number, calculated from the week-based year [defined by the ISO 8601](https://en.wikipedia.org/wiki/ISO_8601#Week_dates) standard, normally useful only with %V | 2018 |
| %g | two-digit year format, aligned to ISO 8601, abbreviated from four-digit notation | 18 |
| %H | hour in 24h format (00-23) | 22 |
| %I | hour in 12h format (01-12) | 10 |
| %j | day of the year (001-366) | 002 |
Expand All @@ -518,6 +530,22 @@ Supported modifiers for Format:
| %Y | Year | 2018 |
| %% | a % sign | % |

AnaUvarova marked this conversation as resolved.
Show resolved Hide resolved
**Example**

Query:

``` sql
SELECT formatDateTime(toDate('2010-01-04'), '%g')
```

Result:

```
┌─formatDateTime(toDate('2010-01-04'), '%g')─┐
│ 10 │
└────────────────────────────────────────────┘
```

[Original article](https://clickhouse.tech/docs/en/query_language/functions/date_time_functions/) <!--hide-->

## FROM_UNIXTIME
Expand Down
40 changes: 34 additions & 6 deletions docs/ru/sql-reference/functions/date-time-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,20 +311,32 @@ SELECT dateDiff('hour', toDateTime('2018-01-01 22:00:00'), toDateTime('2018-01-0
Например, `timeSlots(toDateTime('2012-01-01 12:20:00'), toUInt32(600)) = [toDateTime('2012-01-01 12:00:00'), toDateTime('2012-01-01 12:30:00')]`.
Это нужно для поиска хитов, входящих в соответствующий визит.

## formatDateTime(Time, Format\[, Timezone\]) {#formatdatetime}
## formatDateTime {#formatdatetime}

Функция преобразования даты-с-временем в String согласно заданному шаблону. Важно - шаблон является константным выражением, т.е. невозможно использование разных шаблонов в одной колонке.
Функция преобразует дату-и-время в строку по заданному шаблону. Важно: шаблон — константное выражение, поэтому использовать разные шаблоны в одной колонке не получится.

Поддерживаемые модификаторы в шаблоне Format:
(колонка «Пример» показана для времени `2018-01-02 22:33:44`)
**Синтаксис**

``` sql
formatDateTime(Time, Format\[, Timezone\])
```

**Возвращаемое значение**

Возвращает значение времени и даты в определенном вами формате.

**Поля подстановки**
Используйте поля подстановки для того, чтобы определить шаблон для выводимой строки. В колонке «Пример» результат работы функции для времени `2018-01-02 22:33:44`.

| Модификатор | Описание | Пример |
| Поле | Описание | Пример |
|-------------|----------------------------------------------------------------------|------------|
| %C | номер года, поделённый на 100 (00-99) | 20 |
| %d | день месяца, с ведущим нулём (01-31) | 02 |
| %D | короткая запись %m/%d/%y | 01/02/18 |
| %e | день месяца, с ведущим пробелом ( 1-31) | 2 |
| %F | короткая запись %Y-%m-%d | 2018-01-02 |
| %G | четырехзначный формат вывода ISO-года, который основывается на особом подсчете номера недели согласно [стандарту ISO 8601](https://ru.wikipedia.org/wiki/ISO_8601), обычно используется вместе с %V | 2018 |
| %g | двузначный формат вывода года по стандарту ISO 8601 | 18 |
| %H | час в 24-часовом формате (00-23) | 22 |
| %I | час в 12-часовом формате (01-12) | 10 |
| %j | номер дня в году, с ведущими нулями (001-366) | 002 |
Expand All @@ -343,4 +355,20 @@ SELECT dateDiff('hour', toDateTime('2018-01-01 22:00:00'), toDateTime('2018-01-0
| %Y | год, 4 цифры | 2018 |
| %% | символ % | % |

[Оригинальная статья](https://clickhouse.tech/docs/ru/query_language/functions/date_time_functions/) <!--hide-->
**Пример**

Запрос:

``` sql
SELECT formatDateTime(toDate('2010-01-04'), '%g')
```

Ответ:

```
┌─formatDateTime(toDate('2010-01-04'), '%g')─┐
│ 10 │
└────────────────────────────────────────────┘
```

[Оригинальная статья](https://clickhouse.tech/docs/ru/query_language/functions/date_time_functions/) <!--hide-->