Skip to content

Commit df8ae59

Browse files
authored
docs: DATE_TRUNC updates (#1659)
* Update date-trunc.md * Update date-trunc.md * Update date-trunc.md * Update date-trunc.md * Update date-trunc.md
1 parent 4811177 commit df8ae59

File tree

1 file changed

+19
-15
lines changed
  • docs/en/sql-reference/20-sql-functions/05-datetime-functions

1 file changed

+19
-15
lines changed
Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,37 @@
11
---
22
title: DATE_TRUNC
33
---
4+
import FunctionDescription from '@site/src/components/FunctionDescription';
45

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`.
69

710
## Syntax
811

912
```sql
10-
DATE_TRUNC(<precision>, <date_or_time_expr>)
13+
DATE_TRUNC(<precision>, <date_or_timestamp>)
1114
```
12-
## Arguments
1315

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. |
1820

1921
## Return Type
2022

21-
The function returns a value of the same type as the `<date_or_time_expr>` argument.
23+
Same as `<date_or_timestamp>`.
2224

2325
## Examples
2426

2527
```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-012022-07-04
36+
└────────────────────────────────────────────────────────────────────────────────────┘
3337
```

0 commit comments

Comments
 (0)