|
1 | 1 | ---
|
2 | 2 | title: DATE_TRUNC
|
3 | 3 | ---
|
| 4 | +import FunctionDescription from '@site/src/components/FunctionDescription'; |
4 | 5 |
|
5 |
| -Truncates a date, time, or timestamp value to a specified precision. For example, if you truncate `2022-07-07` to `MONTH`, the result will be `2022-07-01`; if you truncate `2022-07-07 01:01:01.123456` to `SECOND`, the result will be `2022-07-07 01:01:01.000000`. |
| 6 | +<FunctionDescription description="Introduced or updated: v1.2.697"/> |
| 7 | + |
| 8 | +Truncates a date or timestamp to a specified precision. For example, if you truncate `2022-07-07` to `MONTH`, the result will be `2022-07-01`; if you truncate `2022-07-07 01:01:01.123456` to `SECOND`, the result will be `2022-07-07 01:01:01.000000`. |
6 | 9 |
|
7 | 10 | ## Syntax
|
8 | 11 |
|
9 | 12 | ```sql
|
10 |
| -DATE_TRUNC(<precision>, <date_or_time_expr>) |
| 13 | +DATE_TRUNC(<precision>, <date_or_timestamp>) |
11 | 14 | ```
|
12 |
| -## Arguments |
13 | 15 |
|
14 |
| -| Arguments | Description | |
15 |
| -|-----------------------|----------------------------------------------------------------------------------------------------| |
16 |
| -| `<precision>` | Must be of the following values: `YEAR`, `QUARTER`, `MONTH`, `DAY`, `HOUR`, `MINUTE` and `SECOND` | |
17 |
| -| `<date_or_time_expr>` | A value of `DATE` or `TIMESTAMP` type | |
| 16 | +| Parameter | Description | |
| 17 | +|-----------------------|------------------------------------------------------------------------------------------------------------| |
| 18 | +| `<precision>` | Must be of the following values: `YEAR`, `QUARTER`, `MONTH`, `WEEK`, `DAY`, `HOUR`, `MINUTE` and `SECOND`. | |
| 19 | +| `<date_or_timestamp>` | A value of `DATE` or `TIMESTAMP` type. | |
18 | 20 |
|
19 | 21 | ## Return Type
|
20 | 22 |
|
21 |
| -The function returns a value of the same type as the `<date_or_time_expr>` argument. |
| 23 | +Same as `<date_or_timestamp>`. |
22 | 24 |
|
23 | 25 | ## Examples
|
24 | 26 |
|
25 | 27 | ```sql
|
26 |
| -select date_trunc(month, to_date('2022-07-07')); |
27 |
| - |
28 |
| -┌──────────────────────────────────────────┐ |
29 |
| -│ date_trunc(month, to_date('2022-07-07')) │ |
30 |
| -├──────────────────────────────────────────┤ |
31 |
| -│ 2022-07-01 │ |
32 |
| -└──────────────────────────────────────────┘ |
| 28 | +SELECT |
| 29 | + DATE_TRUNC(MONTH, to_date('2022-07-07')), |
| 30 | + DATE_TRUNC(WEEK, to_date('2022-07-07')); |
| 31 | + |
| 32 | +┌────────────────────────────────────────────────────────────────────────────────────┐ |
| 33 | +│ DATE_TRUNC(MONTH, to_date('2022-07-07')) │ DATE_TRUNC(WEEK, to_date('2022-07-07')) │ |
| 34 | +├──────────────────────────────────────────┼─────────────────────────────────────────┤ |
| 35 | +│ 2022-07-01 │ 2022-07-04 │ |
| 36 | +└────────────────────────────────────────────────────────────────────────────────────┘ |
33 | 37 | ```
|
0 commit comments