This is an automated email from the ASF dual-hosted git repository. kassiez pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris-website.git
The following commit(s) were added to refs/heads/master by this push: new d595f972ce1 [Fix](doc) timestamp, years-diff,years-sub,to-iso8601,week-ceil,week-floor (#2189) d595f972ce1 is described below commit d595f972ce15a332504135499a4e075c3a4dee80 Author: bingquanzhao <bingquan_z...@icloud.com> AuthorDate: Wed Apr 23 19:46:35 2025 +0800 [Fix](doc) timestamp, years-diff,years-sub,to-iso8601,week-ceil,week-floor (#2189) ## Versions - [X] dev - [X] 3.0 - [X] 2.1 - [X] 2.0 ## Languages - [X] Chinese - [X] English ## Docs Checklist - [ ] Checked by AI - [ ] Test Cases Built --- .../date-time-functions/timestamp.md | 54 ++++++++++++++++++ .../date-time-functions/to-iso8601.md | 34 ++++++++++++ .../date-time-functions/week-ceil.md | 45 +++++++++++++++ .../date-time-functions/week-floor.md | 45 +++++++++++++++ .../date-time-functions/years-add.md | 34 ++++++++---- .../date-time-functions/years-diff.md | 34 ++++++++---- .../date-time-functions/years-sub.md | 34 ++++++++---- .../date-time-functions/timestamp.md | 54 ++++++++++++++++++ .../date-time-functions/to-iso8601.md | 33 +++++++++++ .../date-time-functions/week-ceil.md | 64 ++++++++++++++++++++++ .../date-time-functions/week-floor.md | 64 ++++++++++++++++++++++ .../date-time-functions/years-add.md | 28 +++++++--- .../date-time-functions/years-diff.md | 28 +++++++--- .../date-time-functions/years-sub.md | 28 +++++++--- .../sql-functions/date-time-functions/years-add.md | 28 +++++++--- .../date-time-functions/years-diff.md | 28 +++++++--- .../sql-functions/date-time-functions/years-sub.md | 28 +++++++--- .../date-time-functions/timestamp.md | 54 ++++++++++++++++++ .../date-time-functions/to-iso8601.md | 33 +++++++++++ .../date-time-functions/week-ceil.md | 64 ++++++++++++++++++++++ .../date-time-functions/week-floor.md | 64 ++++++++++++++++++++++ .../date-time-functions/years-add.md | 28 +++++++--- .../date-time-functions/years-diff.md | 28 +++++++--- .../date-time-functions/years-sub.md | 28 +++++++--- .../date-time-functions/timestamp.md | 54 ++++++++++++++++++ .../date-time-functions/to-iso8601.md | 33 +++++++++++ .../date-time-functions/week-ceil.md | 64 ++++++++++++++++++++++ .../date-time-functions/week-floor.md | 64 ++++++++++++++++++++++ .../date-time-functions/years-add.md | 28 +++++++--- .../date-time-functions/years-diff.md | 28 +++++++--- .../date-time-functions/years-sub.md | 28 +++++++--- .../sql-functions/date-time-functions/years-add.md | 34 ++++++++---- .../date-time-functions/years-diff.md | 34 ++++++++---- .../sql-functions/date-time-functions/years-sub.md | 34 ++++++++---- .../date-time-functions/timestamp.md | 54 ++++++++++++++++++ .../date-time-functions/to-iso8601.md | 34 ++++++++++++ .../date-time-functions/week-ceil.md | 45 +++++++++++++++ .../date-time-functions/week-floor.md | 45 +++++++++++++++ .../date-time-functions/years-add.md | 34 ++++++++---- .../date-time-functions/years-diff.md | 34 ++++++++---- .../date-time-functions/years-sub.md | 34 ++++++++---- .../scalar-functions/string-functions/timestamp.md | 25 --------- .../date-time-functions/timestamp.md | 54 ++++++++++++++++++ .../date-time-functions/to-iso8601.md | 34 ++++++++++++ .../date-time-functions/week-ceil.md | 45 +++++++++++++++ .../date-time-functions/week-floor.md | 45 +++++++++++++++ .../date-time-functions/years-add.md | 34 ++++++++---- .../date-time-functions/years-diff.md | 34 ++++++++---- .../date-time-functions/years-sub.md | 34 ++++++++---- .../scalar-functions/string-functions/timestamp.md | 25 --------- 50 files changed, 1679 insertions(+), 294 deletions(-) diff --git a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/timestamp.md b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/timestamp.md index 0fd806b9080..ad04082cfb4 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/timestamp.md +++ b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/timestamp.md @@ -23,3 +23,57 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> + +## Description + +The TIMESTAMP function has two uses: + +1. Convert a datetime string to a DATETIME type +2. Combine two arguments into a DATETIME type + +## Syntax + +```sql +TIMESTAMP(string) +TIMESTAMP(date, time) +``` + +## Parameters + +| Parameter | Description | +|-----------|--------------------------------------------------| +| `string` | A datetime string | +| `date` | A date value, which can be a DATE type or a properly formatted date string | +| `time` | A time value, which can be a TIME type or a properly formatted time string | + +## Return Value + +Returns a value of type DATETIME. + +## Example + +```sql +-- Convert a string to DATETIME +SELECT TIMESTAMP('2019-01-01 12:00:00'); +``` + +```text ++------------------------------------+ +| timestamp('2019-01-01 12:00:00') | ++------------------------------------+ +| 2019-01-01 12:00:00 | ++------------------------------------+ +``` + +```sql +-- Combine date and time into DATETIME +SELECT TIMESTAMP('2019-01-01', '12:00:00'); +``` + +```text ++----------------------------------------+ +| timestamp('2019-01-01', '12:00:00') | ++----------------------------------------+ +| 2019-01-01 12:00:00 | ++----------------------------------------+ +``` diff --git a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/to-iso8601.md b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/to-iso8601.md index 8d8148f04e8..905f2fcb253 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/to-iso8601.md +++ b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/to-iso8601.md @@ -23,3 +23,37 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> + +## Description + +Converts a datetime value to an ISO8601 formatted string. + +## Syntax + +```sql +TO_ISO8601(<dt>) +``` + +## Parameters + +| Parameter | Description | +|-----------|--------------------------------------------------| +| `<dt>` | The input datetime value, which can be of type DATETIME or DATE | + +## Return Value + +Returns a value of type VARCHAR, representing the datetime in ISO8601 format. + +## Example + +```sql +SELECT TO_ISO8601('2020-01-01 12:30:45'); +``` + +```text ++-------------------------------------+ +| to_iso8601('2020-01-01 12:30:45.0') | ++-------------------------------------+ +| 2020-01-01T12:30:45 | ++-------------------------------------+ +``` diff --git a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/week-ceil.md b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/week-ceil.md index 26abc3cce19..267160f350d 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/week-ceil.md +++ b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/week-ceil.md @@ -23,3 +23,48 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> + +## Description + +Rounds up a datetime value to the nearest specified week interval. If a starting time (origin) is provided, it uses that time as the reference for calculating the interval. + +## Syntax + +```sql +WEEK_CEIL(<datetime>) +WEEK_CEIL(<datetime>, <origin>) +WEEK_CEIL(<datetime>, <period>) +WEEK_CEIL(<datetime>, <period>, <origin>) +``` + +## Parameters + +| Parameter | Description | +|-----------|--------------------------------------------------| +| `<datetime>` | The datetime value to round up, of type DATETIME or DATETIMEV2 | +| `<period>` | The week interval value, of type INT, representing the number of weeks in each interval | +| `<origin>` | The starting point for the interval, of type DATETIME or DATETIMEV2; defaults to 0001-01-01 00:00:00 | + +## Return Value + +Returns a value of type DATETIME, representing the rounded-up datetime value. The time portion of the result will be set to 00:00:00. + +**Note:** +- If no period is specified, it defaults to a 1-week interval. +- The period must be a positive integer. +- The result is always rounded up to a future time. +- The time portion of the returned value is always set to 00:00:00. + +## Example + +```sql +SELECT WEEK_CEIL('2023-07-13 22:28:18', 2); +``` + +```text ++-----------------------------------------------------------+ +| week_ceil(cast('2023-07-13 22:28:18' as DATETIMEV2(0)), 2) | ++-----------------------------------------------------------+ +| 2023-07-17 00:00:00 | ++-----------------------------------------------------------+ +``` diff --git a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/week-floor.md b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/week-floor.md index d02e4cc1e5d..ddf255f6b39 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/week-floor.md +++ b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/week-floor.md @@ -23,3 +23,48 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> + +## Description + +Rounds down a datetime value to the nearest specified week interval. If a starting time (origin) is provided, it uses that time as the reference for calculating the interval. + +## Syntax + +```sql +WEEK_FLOOR(<datetime>) +WEEK_FLOOR(<datetime>, <origin>) +WEEK_FLOOR(<datetime>, <period>) +WEEK_FLOOR(<datetime>, <period>, <origin>) +``` + +## Parameters + +| Parameter | Description | +|-----------|--------------------------------------------------| +| `<datetime>` | The datetime value to round down, of type DATETIME or DATETIMEV2 | +| `<period>` | The week interval value, of type INT, representing the number of weeks in each interval | +| `<origin>` | The starting point for the interval, of type DATETIME or DATETIMEV2; defaults to 0001-01-01 00:00:00 | + +## Return Value + +Returns a value of type DATETIME, representing the rounded-down datetime value. The time portion of the result will be set to 00:00:00. + +**Note:** +- If no period is specified, it defaults to a 1-week interval. +- The period must be a positive integer. +- The result is always rounded down to a past time. +- The time portion of the returned value is always set to 00:00:00. + +## Example + +```sql +SELECT WEEK_FLOOR('2023-07-13 22:28:18', 2); +``` + +```text ++------------------------------------------------------------+ +| week_floor(cast('2023-07-13 22:28:18' as DATETIMEV2(0)), 2) | ++------------------------------------------------------------+ +| 2023-07-03 00:00:00 | ++------------------------------------------------------------+ +``` diff --git a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/years-add.md b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/years-add.md index 7b9a7cc5b91..1a72b332964 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/years-add.md +++ b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/years-add.md @@ -24,27 +24,37 @@ specific language governing permissions and limitations under the License. --> -## years_add -### description -#### Syntax +## Description -`DATETIME YEARS_ADD(DATETIME date, INT years)` +Returns a new datetime value that is the result of adding a specified number of years to the input datetime. -ADD a specified number of years from a datetime or date +## Syntax -The parameter date can be DATETIME or DATE, and the return type is consistent with that of the parameter date. +```sql +YEARS_ADD(<date>, <years>) +``` + +## Parameters + +| Parameter | Description | +|-----------|--------------------------------------------------| +| `<date>` | The input datetime value, which can be of type DATETIME or DATE | +| `<years>` | The number of years to add, of type INT | + +## Return Value -### example +Returns a value with the same type as the input `<date>` (DATETIME or DATE), representing the time value after adding the specified number of years to the input datetime. +## Example + +```sql +SELECT YEARS_ADD('2020-01-31 02:02:02', 1); ``` -mysql> select years_add("2020-01-31 02:02:02", 1); + +```text +-------------------------------------+ | years_add('2020-01-31 02:02:02', 1) | +-------------------------------------+ | 2021-01-31 02:02:02 | +-------------------------------------+ ``` - -### keywords - - YEARS_ADD diff --git a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/years-diff.md b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/years-diff.md index bb787b64096..da87f045dee 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/years-diff.md +++ b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/years-diff.md @@ -24,25 +24,37 @@ specific language governing permissions and limitations under the License. --> -## years_diff -### description -#### Syntax +## Description -`INT years_diff(DATETIME enddate, DATETIME startdate)` +Calculates the difference in years between two datetime values. -The difference between the start time and the end time is several years +## Syntax -### example +```sql +YEARS_DIFF(<enddate>, <startdate>) +``` + +## Parameters + +| Parameter | Description | +|-----------|--------------------------------------------------| +| `<enddate>` | The end date, which can be of type DATETIME or DATE | +| `<startdate>` | The start date, which can be of type DATETIME or DATE | + +## Return Value + +Returns a value of type INT, representing the number of years between the two dates. +## Example + +```sql +SELECT YEARS_DIFF('2020-12-25', '2019-10-25'); ``` -mysql> select years_diff('2020-12-25','2019-10-25'); + +```text +----------------------------------------------------------+ | years_diff('2020-12-25 00:00:00', '2019-10-25 00:00:00') | +----------------------------------------------------------+ | 1 | +----------------------------------------------------------+ ``` - -### keywords - - years_diff diff --git a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/years-sub.md b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/years-sub.md index 7cd68cf4a7a..cc6c940f6e5 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/years-sub.md +++ b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/years-sub.md @@ -24,27 +24,37 @@ specific language governing permissions and limitations under the License. --> -## years_sub -### description -#### Syntax +## Description -`DATETIME YEARS_SUB(DATETIME date, INT years)` +Returns a new datetime value that is the result of subtracting a specified number of years from the input datetime. -Subtracts a specified number of years from a datetime or date +## Syntax -The parameter date can be DATETIME or DATE, and the return type is consistent with that of the parameter date. +```sql +YEARS_SUB(<date>, <years>) +``` + +## Parameters + +| Parameter | Description | +|-----------|--------------------------------------------------| +| `<date>` | The input datetime value, which can be of type DATETIME or DATE | +| `<years>` | The number of years to subtract, of type INT | + +## Return Value -### example +Returns a value with the same type as the input `<date>` (DATETIME or DATE), representing the time value after subtracting the specified number of years from the input datetime. +## Example + +```sql +SELECT YEARS_SUB('2020-02-02 02:02:02', 1); ``` -mysql> select years_sub("2020-02-02 02:02:02", 1); + +```text +-------------------------------------+ | years_sub('2020-02-02 02:02:02', 1) | +-------------------------------------+ | 2019-02-02 02:02:02 | +-------------------------------------+ ``` - -### keywords - - YEARS_SUB diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/timestamp.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/timestamp.md index 1c0fb28318a..bec12460531 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/timestamp.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/timestamp.md @@ -23,3 +23,57 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> + +## 描述 + +TIMESTAMP 函数有两种用法: + +1. 将日期时间字符串转换为 DATETIME 类型 +2. 将两个参数组合成一个 DATETIME 类型 + +## 语法 + +```sql +TIMESTAMP(string) +TIMESTAMP(date, time) +``` + +## 参数 + +| 参数 | 说明 | +| ---- | ---- | +| `string` | 日期时间字符串 | +| `date` | 日期值,可以是 DATE 类型或格式正确的日期字符串 | +| `time` | 时间值,可以是 TIME 类型或格式正确的时间字符串 | + +## 返回值 + +返回类型为 DATETIME。 + +## 举例 + +```sql +-- 将字符串转换为 DATETIME +SELECT TIMESTAMP('2019-01-01 12:00:00'); +``` + +```text ++------------------------------------+ +| timestamp('2019-01-01 12:00:00') | ++------------------------------------+ +| 2019-01-01 12:00:00 | ++------------------------------------+ +``` + +```sql +-- 将日期和时间组合成 DATETIME +SELECT TIMESTAMP('2019-01-01', '12:00:00'); +``` + +```text ++----------------------------------------+ +| timestamp('2019-01-01', '12:00:00') | ++----------------------------------------+ +| 2019-01-01 12:00:00 | ++----------------------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/to-iso8601.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/to-iso8601.md index 7d54edd9610..59a64d65380 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/to-iso8601.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/to-iso8601.md @@ -24,3 +24,36 @@ specific language governing permissions and limitations under the License. --> +## 描述 + +将日期时间值转换为 ISO8601 格式的字符串。 + +## 语法 + +```sql +TO_ISO8601(<dt>) +``` + +## 参数 + +| 参数 | 说明 | +| ---- | ---- | +| `<dt>` | 输入的日期时间值,类型为 DATETIME 或 DATE | + +## 返回值 + +返回类型为 VARCHAR,表示 ISO8601 格式的日期时间字符串。 + +## 举例 + +```sql +SELECT TO_ISO8601('2020-01-01 12:30:45'); +``` + +```text ++-------------------------------------+ +| to_iso8601('2020-01-01 12:30:45.0') | ++-------------------------------------+ +| 2020-01-01T12:30:45 | ++-------------------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/week-ceil.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/week-ceil.md index d56571ab223..d5db7b2bf18 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/week-ceil.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/week-ceil.md @@ -4,3 +4,67 @@ "language": "zh-CN" } --- + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +## 描述 + +将日期时间值向上舍入到最接近的指定周间隔。如果提供了起始时间(origin),则使用该时间作为计算间隔的参考点。 + +## 语法 + +```sql +WEEK_CEIL(<datetime>) +WEEK_CEIL(<datetime>, <origin>) +WEEK_CEIL(<datetime>, <period>) +WEEK_CEIL(<datetime>, <period>, <origin>) +``` + +## 参数 + +| 参数 | 说明 | +| ---- | ---- | +| `<datetime>` | 要向上舍入的日期时间值,类型为 DATETIME 或 DATETIMEV2 | +| `<period>` | 周间隔值,类型为 INT,表示每个间隔的周数 | +| `<origin>` | 间隔的起始点,类型为 DATETIME 或 DATETIMEV2;默认为 0001-01-01 00:00:00 | + +## 返回值 + +返回类型为 DATETIME,表示向上舍入后的日期时间值。结果的时间部分将被设置为 00:00:00。 + +**注意:** +- 如果未指定周期,则默认为 1 周间隔。 +- 周期必须是正整数。 +- 结果总是向上舍入到未来的时间。 +- 返回值的时间部分始终设置为 00:00:00。 + +## 举例 + +```sql +SELECT WEEK_CEIL('2023-07-13 22:28:18', 2); +``` + +```text ++-----------------------------------------------------------+ +| week_ceil(cast('2023-07-13 22:28:18' as DATETIMEV2(0)), 2) | ++-----------------------------------------------------------+ +| 2023-07-17 00:00:00 | ++-----------------------------------------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/week-floor.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/week-floor.md index abc059c1395..a041157b5ef 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/week-floor.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/week-floor.md @@ -4,3 +4,67 @@ "language": "zh-CN" } --- + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +## 描述 + +将日期时间值向下舍入到最接近的指定周间隔。如果提供了起始时间(origin),则使用该时间作为计算间隔的参考点。 + +## 语法 + +```sql +WEEK_FLOOR(<datetime>) +WEEK_FLOOR(<datetime>, <origin>) +WEEK_FLOOR(<datetime>, <period>) +WEEK_FLOOR(<datetime>, <period>, <origin>) +``` + +## 参数 + +| 参数 | 说明 | +| ---- | ---- | +| `<datetime>` | 要向下舍入的日期时间值,类型为 DATETIME 或 DATETIMEV2 | +| `<period>` | 周间隔值,类型为 INT,表示每个间隔的周数 | +| `<origin>` | 间隔的起始点,类型为 DATETIME 或 DATETIMEV2;默认为 0001-01-01 00:00:00 | + +## 返回值 + +返回类型为 DATETIME,表示向下舍入后的日期时间值。结果的时间部分将被设置为 00:00:00。 + +**注意:** +- 如果未指定周期,则默认为 1 周间隔。 +- 周期必须是正整数。 +- 结果总是向下舍入到过去的时间。 +- 返回值的时间部分始终设置为 00:00:00。 + +## 举例 + +```sql +SELECT WEEK_FLOOR('2023-07-13 22:28:18', 2); +``` + +```text ++------------------------------------------------------------+ +| week_floor(cast('2023-07-13 22:28:18' as DATETIMEV2(0)), 2) | ++------------------------------------------------------------+ +| 2023-07-03 00:00:00 | ++------------------------------------------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/years-add.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/years-add.md index d0bbab76dbc..2bedb0166ba 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/years-add.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/years-add.md @@ -24,27 +24,37 @@ specific language governing permissions and limitations under the License. --> -## years_add ## 描述 + +返回一个新的日期时间值,该值是在输入的日期时间上增加指定的年数。 + ## 语法 -`DATETIME YEARS_ADD(DATETIME date, INT years)` +```sql +YEARS_ADD(<date>, <years>) +``` + +## 参数 -从日期加上指定年数 +| 参数 | 说明 | +| ---- | ---- | +| `<date>` | 输入的日期时间值,类型为 DATETIME 或 DATE | +| `<years>` | 要增加的年数,类型为 INT | -参数 date 可以是 DATETIME 或者 DATE 类型,返回类型与参数 date 的类型一致。 +## 返回值 + +返回与输入 `<date>` 类型相同的值(DATETIME 或 DATE),表示在输入日期时间的基础上增加指定年数后的时间值。 ## 举例 +```sql +SELECT YEARS_ADD('2020-01-31 02:02:02', 1); ``` -mysql> select years_add("2020-01-31 02:02:02", 1); + +```text +-------------------------------------+ | years_add('2020-01-31 02:02:02', 1) | +-------------------------------------+ | 2021-01-31 02:02:02 | +-------------------------------------+ ``` - -### keywords - - YEARS_ADD diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/years-diff.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/years-diff.md index d9508663811..dc2716d546e 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/years-diff.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/years-diff.md @@ -24,25 +24,37 @@ specific language governing permissions and limitations under the License. --> -## years_diff ## 描述 + +计算两个日期时间值之间相差的年数。 + ## 语法 -`INT years_diff(DATETIME enddate, DATETIME startdate)` +```sql +YEARS_DIFF(<enddate>, <startdate>) +``` + +## 参数 + +| 参数 | 说明 | +| ---- | ---- | +| `<enddate>` | 结束日期,类型为 DATETIME 或 DATE | +| `<startdate>` | 开始日期,类型为 DATETIME 或 DATE | -开始时间到结束时间相差几年 +## 返回值 + +返回类型为 INT,表示两个日期之间相差的年数。 ## 举例 +```sql +SELECT YEARS_DIFF('2020-12-25', '2019-10-25'); ``` -mysql> select years_diff('2020-12-25','2019-10-25'); + +```text +----------------------------------------------------------+ | years_diff('2020-12-25 00:00:00', '2019-10-25 00:00:00') | +----------------------------------------------------------+ | 1 | +----------------------------------------------------------+ ``` - -### keywords - - years_diff diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/years-sub.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/years-sub.md index 7c05bc24762..bd42896c9af 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/years-sub.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/years-sub.md @@ -24,27 +24,37 @@ specific language governing permissions and limitations under the License. --> -## years_sub ## 描述 + +返回一个新的日期时间值,该值是从输入的日期时间中减去指定的年数。 + ## 语法 -`DATETIME YEARS_SUB(DATETIME date, INT years)` +```sql +YEARS_SUB(<date>, <years>) +``` + +## 参数 -从日期时间或日期减去指定年数 +| 参数 | 说明 | +| ---- | ---- | +| `<date>` | 输入的日期时间值,类型为 DATETIME 或 DATE | +| `<years>` | 要减去的年数,类型为 INT | -参数 date 可以是 DATETIME 或者 DATE 类型,返回类型与参数 date 的类型一致。 +## 返回值 + +返回与输入 `<date>` 类型相同的值(DATETIME 或 DATE),表示从输入日期时间中减去指定年数后的时间值。 ## 举例 +```sql +SELECT YEARS_SUB('2020-02-02 02:02:02', 1); ``` -mysql> select years_sub("2020-02-02 02:02:02", 1); + +```text +-------------------------------------+ | years_sub('2020-02-02 02:02:02', 1) | +-------------------------------------+ | 2019-02-02 02:02:02 | +-------------------------------------+ ``` - -### keywords - - YEARS_SUB diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/date-time-functions/years-add.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/date-time-functions/years-add.md index d0bbab76dbc..2bedb0166ba 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/date-time-functions/years-add.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/date-time-functions/years-add.md @@ -24,27 +24,37 @@ specific language governing permissions and limitations under the License. --> -## years_add ## 描述 + +返回一个新的日期时间值,该值是在输入的日期时间上增加指定的年数。 + ## 语法 -`DATETIME YEARS_ADD(DATETIME date, INT years)` +```sql +YEARS_ADD(<date>, <years>) +``` + +## 参数 -从日期加上指定年数 +| 参数 | 说明 | +| ---- | ---- | +| `<date>` | 输入的日期时间值,类型为 DATETIME 或 DATE | +| `<years>` | 要增加的年数,类型为 INT | -参数 date 可以是 DATETIME 或者 DATE 类型,返回类型与参数 date 的类型一致。 +## 返回值 + +返回与输入 `<date>` 类型相同的值(DATETIME 或 DATE),表示在输入日期时间的基础上增加指定年数后的时间值。 ## 举例 +```sql +SELECT YEARS_ADD('2020-01-31 02:02:02', 1); ``` -mysql> select years_add("2020-01-31 02:02:02", 1); + +```text +-------------------------------------+ | years_add('2020-01-31 02:02:02', 1) | +-------------------------------------+ | 2021-01-31 02:02:02 | +-------------------------------------+ ``` - -### keywords - - YEARS_ADD diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/date-time-functions/years-diff.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/date-time-functions/years-diff.md index d9508663811..dc2716d546e 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/date-time-functions/years-diff.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/date-time-functions/years-diff.md @@ -24,25 +24,37 @@ specific language governing permissions and limitations under the License. --> -## years_diff ## 描述 + +计算两个日期时间值之间相差的年数。 + ## 语法 -`INT years_diff(DATETIME enddate, DATETIME startdate)` +```sql +YEARS_DIFF(<enddate>, <startdate>) +``` + +## 参数 + +| 参数 | 说明 | +| ---- | ---- | +| `<enddate>` | 结束日期,类型为 DATETIME 或 DATE | +| `<startdate>` | 开始日期,类型为 DATETIME 或 DATE | -开始时间到结束时间相差几年 +## 返回值 + +返回类型为 INT,表示两个日期之间相差的年数。 ## 举例 +```sql +SELECT YEARS_DIFF('2020-12-25', '2019-10-25'); ``` -mysql> select years_diff('2020-12-25','2019-10-25'); + +```text +----------------------------------------------------------+ | years_diff('2020-12-25 00:00:00', '2019-10-25 00:00:00') | +----------------------------------------------------------+ | 1 | +----------------------------------------------------------+ ``` - -### keywords - - years_diff diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/date-time-functions/years-sub.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/date-time-functions/years-sub.md index 7c05bc24762..bd42896c9af 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/date-time-functions/years-sub.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.0/sql-manual/sql-functions/date-time-functions/years-sub.md @@ -24,27 +24,37 @@ specific language governing permissions and limitations under the License. --> -## years_sub ## 描述 + +返回一个新的日期时间值,该值是从输入的日期时间中减去指定的年数。 + ## 语法 -`DATETIME YEARS_SUB(DATETIME date, INT years)` +```sql +YEARS_SUB(<date>, <years>) +``` + +## 参数 -从日期时间或日期减去指定年数 +| 参数 | 说明 | +| ---- | ---- | +| `<date>` | 输入的日期时间值,类型为 DATETIME 或 DATE | +| `<years>` | 要减去的年数,类型为 INT | -参数 date 可以是 DATETIME 或者 DATE 类型,返回类型与参数 date 的类型一致。 +## 返回值 + +返回与输入 `<date>` 类型相同的值(DATETIME 或 DATE),表示从输入日期时间中减去指定年数后的时间值。 ## 举例 +```sql +SELECT YEARS_SUB('2020-02-02 02:02:02', 1); ``` -mysql> select years_sub("2020-02-02 02:02:02", 1); + +```text +-------------------------------------+ | years_sub('2020-02-02 02:02:02', 1) | +-------------------------------------+ | 2019-02-02 02:02:02 | +-------------------------------------+ ``` - -### keywords - - YEARS_SUB diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestamp.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestamp.md index 1c0fb28318a..bec12460531 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestamp.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestamp.md @@ -23,3 +23,57 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> + +## 描述 + +TIMESTAMP 函数有两种用法: + +1. 将日期时间字符串转换为 DATETIME 类型 +2. 将两个参数组合成一个 DATETIME 类型 + +## 语法 + +```sql +TIMESTAMP(string) +TIMESTAMP(date, time) +``` + +## 参数 + +| 参数 | 说明 | +| ---- | ---- | +| `string` | 日期时间字符串 | +| `date` | 日期值,可以是 DATE 类型或格式正确的日期字符串 | +| `time` | 时间值,可以是 TIME 类型或格式正确的时间字符串 | + +## 返回值 + +返回类型为 DATETIME。 + +## 举例 + +```sql +-- 将字符串转换为 DATETIME +SELECT TIMESTAMP('2019-01-01 12:00:00'); +``` + +```text ++------------------------------------+ +| timestamp('2019-01-01 12:00:00') | ++------------------------------------+ +| 2019-01-01 12:00:00 | ++------------------------------------+ +``` + +```sql +-- 将日期和时间组合成 DATETIME +SELECT TIMESTAMP('2019-01-01', '12:00:00'); +``` + +```text ++----------------------------------------+ +| timestamp('2019-01-01', '12:00:00') | ++----------------------------------------+ +| 2019-01-01 12:00:00 | ++----------------------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/to-iso8601.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/to-iso8601.md index 7d54edd9610..59a64d65380 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/to-iso8601.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/to-iso8601.md @@ -24,3 +24,36 @@ specific language governing permissions and limitations under the License. --> +## 描述 + +将日期时间值转换为 ISO8601 格式的字符串。 + +## 语法 + +```sql +TO_ISO8601(<dt>) +``` + +## 参数 + +| 参数 | 说明 | +| ---- | ---- | +| `<dt>` | 输入的日期时间值,类型为 DATETIME 或 DATE | + +## 返回值 + +返回类型为 VARCHAR,表示 ISO8601 格式的日期时间字符串。 + +## 举例 + +```sql +SELECT TO_ISO8601('2020-01-01 12:30:45'); +``` + +```text ++-------------------------------------+ +| to_iso8601('2020-01-01 12:30:45.0') | ++-------------------------------------+ +| 2020-01-01T12:30:45 | ++-------------------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/week-ceil.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/week-ceil.md index d56571ab223..d5db7b2bf18 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/week-ceil.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/week-ceil.md @@ -4,3 +4,67 @@ "language": "zh-CN" } --- + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +## 描述 + +将日期时间值向上舍入到最接近的指定周间隔。如果提供了起始时间(origin),则使用该时间作为计算间隔的参考点。 + +## 语法 + +```sql +WEEK_CEIL(<datetime>) +WEEK_CEIL(<datetime>, <origin>) +WEEK_CEIL(<datetime>, <period>) +WEEK_CEIL(<datetime>, <period>, <origin>) +``` + +## 参数 + +| 参数 | 说明 | +| ---- | ---- | +| `<datetime>` | 要向上舍入的日期时间值,类型为 DATETIME 或 DATETIMEV2 | +| `<period>` | 周间隔值,类型为 INT,表示每个间隔的周数 | +| `<origin>` | 间隔的起始点,类型为 DATETIME 或 DATETIMEV2;默认为 0001-01-01 00:00:00 | + +## 返回值 + +返回类型为 DATETIME,表示向上舍入后的日期时间值。结果的时间部分将被设置为 00:00:00。 + +**注意:** +- 如果未指定周期,则默认为 1 周间隔。 +- 周期必须是正整数。 +- 结果总是向上舍入到未来的时间。 +- 返回值的时间部分始终设置为 00:00:00。 + +## 举例 + +```sql +SELECT WEEK_CEIL('2023-07-13 22:28:18', 2); +``` + +```text ++-----------------------------------------------------------+ +| week_ceil(cast('2023-07-13 22:28:18' as DATETIMEV2(0)), 2) | ++-----------------------------------------------------------+ +| 2023-07-17 00:00:00 | ++-----------------------------------------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/week-floor.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/week-floor.md index abc059c1395..a041157b5ef 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/week-floor.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/week-floor.md @@ -4,3 +4,67 @@ "language": "zh-CN" } --- + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +## 描述 + +将日期时间值向下舍入到最接近的指定周间隔。如果提供了起始时间(origin),则使用该时间作为计算间隔的参考点。 + +## 语法 + +```sql +WEEK_FLOOR(<datetime>) +WEEK_FLOOR(<datetime>, <origin>) +WEEK_FLOOR(<datetime>, <period>) +WEEK_FLOOR(<datetime>, <period>, <origin>) +``` + +## 参数 + +| 参数 | 说明 | +| ---- | ---- | +| `<datetime>` | 要向下舍入的日期时间值,类型为 DATETIME 或 DATETIMEV2 | +| `<period>` | 周间隔值,类型为 INT,表示每个间隔的周数 | +| `<origin>` | 间隔的起始点,类型为 DATETIME 或 DATETIMEV2;默认为 0001-01-01 00:00:00 | + +## 返回值 + +返回类型为 DATETIME,表示向下舍入后的日期时间值。结果的时间部分将被设置为 00:00:00。 + +**注意:** +- 如果未指定周期,则默认为 1 周间隔。 +- 周期必须是正整数。 +- 结果总是向下舍入到过去的时间。 +- 返回值的时间部分始终设置为 00:00:00。 + +## 举例 + +```sql +SELECT WEEK_FLOOR('2023-07-13 22:28:18', 2); +``` + +```text ++------------------------------------------------------------+ +| week_floor(cast('2023-07-13 22:28:18' as DATETIMEV2(0)), 2) | ++------------------------------------------------------------+ +| 2023-07-03 00:00:00 | ++------------------------------------------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/years-add.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/years-add.md index d0bbab76dbc..2bedb0166ba 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/years-add.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/years-add.md @@ -24,27 +24,37 @@ specific language governing permissions and limitations under the License. --> -## years_add ## 描述 + +返回一个新的日期时间值,该值是在输入的日期时间上增加指定的年数。 + ## 语法 -`DATETIME YEARS_ADD(DATETIME date, INT years)` +```sql +YEARS_ADD(<date>, <years>) +``` + +## 参数 -从日期加上指定年数 +| 参数 | 说明 | +| ---- | ---- | +| `<date>` | 输入的日期时间值,类型为 DATETIME 或 DATE | +| `<years>` | 要增加的年数,类型为 INT | -参数 date 可以是 DATETIME 或者 DATE 类型,返回类型与参数 date 的类型一致。 +## 返回值 + +返回与输入 `<date>` 类型相同的值(DATETIME 或 DATE),表示在输入日期时间的基础上增加指定年数后的时间值。 ## 举例 +```sql +SELECT YEARS_ADD('2020-01-31 02:02:02', 1); ``` -mysql> select years_add("2020-01-31 02:02:02", 1); + +```text +-------------------------------------+ | years_add('2020-01-31 02:02:02', 1) | +-------------------------------------+ | 2021-01-31 02:02:02 | +-------------------------------------+ ``` - -### keywords - - YEARS_ADD diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/years-diff.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/years-diff.md index d9508663811..dc2716d546e 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/years-diff.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/years-diff.md @@ -24,25 +24,37 @@ specific language governing permissions and limitations under the License. --> -## years_diff ## 描述 + +计算两个日期时间值之间相差的年数。 + ## 语法 -`INT years_diff(DATETIME enddate, DATETIME startdate)` +```sql +YEARS_DIFF(<enddate>, <startdate>) +``` + +## 参数 + +| 参数 | 说明 | +| ---- | ---- | +| `<enddate>` | 结束日期,类型为 DATETIME 或 DATE | +| `<startdate>` | 开始日期,类型为 DATETIME 或 DATE | -开始时间到结束时间相差几年 +## 返回值 + +返回类型为 INT,表示两个日期之间相差的年数。 ## 举例 +```sql +SELECT YEARS_DIFF('2020-12-25', '2019-10-25'); ``` -mysql> select years_diff('2020-12-25','2019-10-25'); + +```text +----------------------------------------------------------+ | years_diff('2020-12-25 00:00:00', '2019-10-25 00:00:00') | +----------------------------------------------------------+ | 1 | +----------------------------------------------------------+ ``` - -### keywords - - years_diff diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/years-sub.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/years-sub.md index 7c05bc24762..bd42896c9af 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/years-sub.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/years-sub.md @@ -24,27 +24,37 @@ specific language governing permissions and limitations under the License. --> -## years_sub ## 描述 + +返回一个新的日期时间值,该值是从输入的日期时间中减去指定的年数。 + ## 语法 -`DATETIME YEARS_SUB(DATETIME date, INT years)` +```sql +YEARS_SUB(<date>, <years>) +``` + +## 参数 -从日期时间或日期减去指定年数 +| 参数 | 说明 | +| ---- | ---- | +| `<date>` | 输入的日期时间值,类型为 DATETIME 或 DATE | +| `<years>` | 要减去的年数,类型为 INT | -参数 date 可以是 DATETIME 或者 DATE 类型,返回类型与参数 date 的类型一致。 +## 返回值 + +返回与输入 `<date>` 类型相同的值(DATETIME 或 DATE),表示从输入日期时间中减去指定年数后的时间值。 ## 举例 +```sql +SELECT YEARS_SUB('2020-02-02 02:02:02', 1); ``` -mysql> select years_sub("2020-02-02 02:02:02", 1); + +```text +-------------------------------------+ | years_sub('2020-02-02 02:02:02', 1) | +-------------------------------------+ | 2019-02-02 02:02:02 | +-------------------------------------+ ``` - -### keywords - - YEARS_SUB diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestamp.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestamp.md index 1c0fb28318a..bec12460531 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestamp.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestamp.md @@ -23,3 +23,57 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> + +## 描述 + +TIMESTAMP 函数有两种用法: + +1. 将日期时间字符串转换为 DATETIME 类型 +2. 将两个参数组合成一个 DATETIME 类型 + +## 语法 + +```sql +TIMESTAMP(string) +TIMESTAMP(date, time) +``` + +## 参数 + +| 参数 | 说明 | +| ---- | ---- | +| `string` | 日期时间字符串 | +| `date` | 日期值,可以是 DATE 类型或格式正确的日期字符串 | +| `time` | 时间值,可以是 TIME 类型或格式正确的时间字符串 | + +## 返回值 + +返回类型为 DATETIME。 + +## 举例 + +```sql +-- 将字符串转换为 DATETIME +SELECT TIMESTAMP('2019-01-01 12:00:00'); +``` + +```text ++------------------------------------+ +| timestamp('2019-01-01 12:00:00') | ++------------------------------------+ +| 2019-01-01 12:00:00 | ++------------------------------------+ +``` + +```sql +-- 将日期和时间组合成 DATETIME +SELECT TIMESTAMP('2019-01-01', '12:00:00'); +``` + +```text ++----------------------------------------+ +| timestamp('2019-01-01', '12:00:00') | ++----------------------------------------+ +| 2019-01-01 12:00:00 | ++----------------------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/to-iso8601.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/to-iso8601.md index 7d54edd9610..59a64d65380 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/to-iso8601.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/to-iso8601.md @@ -24,3 +24,36 @@ specific language governing permissions and limitations under the License. --> +## 描述 + +将日期时间值转换为 ISO8601 格式的字符串。 + +## 语法 + +```sql +TO_ISO8601(<dt>) +``` + +## 参数 + +| 参数 | 说明 | +| ---- | ---- | +| `<dt>` | 输入的日期时间值,类型为 DATETIME 或 DATE | + +## 返回值 + +返回类型为 VARCHAR,表示 ISO8601 格式的日期时间字符串。 + +## 举例 + +```sql +SELECT TO_ISO8601('2020-01-01 12:30:45'); +``` + +```text ++-------------------------------------+ +| to_iso8601('2020-01-01 12:30:45.0') | ++-------------------------------------+ +| 2020-01-01T12:30:45 | ++-------------------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/week-ceil.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/week-ceil.md index d56571ab223..d5db7b2bf18 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/week-ceil.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/week-ceil.md @@ -4,3 +4,67 @@ "language": "zh-CN" } --- + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +## 描述 + +将日期时间值向上舍入到最接近的指定周间隔。如果提供了起始时间(origin),则使用该时间作为计算间隔的参考点。 + +## 语法 + +```sql +WEEK_CEIL(<datetime>) +WEEK_CEIL(<datetime>, <origin>) +WEEK_CEIL(<datetime>, <period>) +WEEK_CEIL(<datetime>, <period>, <origin>) +``` + +## 参数 + +| 参数 | 说明 | +| ---- | ---- | +| `<datetime>` | 要向上舍入的日期时间值,类型为 DATETIME 或 DATETIMEV2 | +| `<period>` | 周间隔值,类型为 INT,表示每个间隔的周数 | +| `<origin>` | 间隔的起始点,类型为 DATETIME 或 DATETIMEV2;默认为 0001-01-01 00:00:00 | + +## 返回值 + +返回类型为 DATETIME,表示向上舍入后的日期时间值。结果的时间部分将被设置为 00:00:00。 + +**注意:** +- 如果未指定周期,则默认为 1 周间隔。 +- 周期必须是正整数。 +- 结果总是向上舍入到未来的时间。 +- 返回值的时间部分始终设置为 00:00:00。 + +## 举例 + +```sql +SELECT WEEK_CEIL('2023-07-13 22:28:18', 2); +``` + +```text ++-----------------------------------------------------------+ +| week_ceil(cast('2023-07-13 22:28:18' as DATETIMEV2(0)), 2) | ++-----------------------------------------------------------+ +| 2023-07-17 00:00:00 | ++-----------------------------------------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/week-floor.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/week-floor.md index abc059c1395..a041157b5ef 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/week-floor.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/week-floor.md @@ -4,3 +4,67 @@ "language": "zh-CN" } --- + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +## 描述 + +将日期时间值向下舍入到最接近的指定周间隔。如果提供了起始时间(origin),则使用该时间作为计算间隔的参考点。 + +## 语法 + +```sql +WEEK_FLOOR(<datetime>) +WEEK_FLOOR(<datetime>, <origin>) +WEEK_FLOOR(<datetime>, <period>) +WEEK_FLOOR(<datetime>, <period>, <origin>) +``` + +## 参数 + +| 参数 | 说明 | +| ---- | ---- | +| `<datetime>` | 要向下舍入的日期时间值,类型为 DATETIME 或 DATETIMEV2 | +| `<period>` | 周间隔值,类型为 INT,表示每个间隔的周数 | +| `<origin>` | 间隔的起始点,类型为 DATETIME 或 DATETIMEV2;默认为 0001-01-01 00:00:00 | + +## 返回值 + +返回类型为 DATETIME,表示向下舍入后的日期时间值。结果的时间部分将被设置为 00:00:00。 + +**注意:** +- 如果未指定周期,则默认为 1 周间隔。 +- 周期必须是正整数。 +- 结果总是向下舍入到过去的时间。 +- 返回值的时间部分始终设置为 00:00:00。 + +## 举例 + +```sql +SELECT WEEK_FLOOR('2023-07-13 22:28:18', 2); +``` + +```text ++------------------------------------------------------------+ +| week_floor(cast('2023-07-13 22:28:18' as DATETIMEV2(0)), 2) | ++------------------------------------------------------------+ +| 2023-07-03 00:00:00 | ++------------------------------------------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/years-add.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/years-add.md index d0bbab76dbc..2bedb0166ba 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/years-add.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/years-add.md @@ -24,27 +24,37 @@ specific language governing permissions and limitations under the License. --> -## years_add ## 描述 + +返回一个新的日期时间值,该值是在输入的日期时间上增加指定的年数。 + ## 语法 -`DATETIME YEARS_ADD(DATETIME date, INT years)` +```sql +YEARS_ADD(<date>, <years>) +``` + +## 参数 -从日期加上指定年数 +| 参数 | 说明 | +| ---- | ---- | +| `<date>` | 输入的日期时间值,类型为 DATETIME 或 DATE | +| `<years>` | 要增加的年数,类型为 INT | -参数 date 可以是 DATETIME 或者 DATE 类型,返回类型与参数 date 的类型一致。 +## 返回值 + +返回与输入 `<date>` 类型相同的值(DATETIME 或 DATE),表示在输入日期时间的基础上增加指定年数后的时间值。 ## 举例 +```sql +SELECT YEARS_ADD('2020-01-31 02:02:02', 1); ``` -mysql> select years_add("2020-01-31 02:02:02", 1); + +```text +-------------------------------------+ | years_add('2020-01-31 02:02:02', 1) | +-------------------------------------+ | 2021-01-31 02:02:02 | +-------------------------------------+ ``` - -### keywords - - YEARS_ADD diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/years-diff.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/years-diff.md index d9508663811..dc2716d546e 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/years-diff.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/years-diff.md @@ -24,25 +24,37 @@ specific language governing permissions and limitations under the License. --> -## years_diff ## 描述 + +计算两个日期时间值之间相差的年数。 + ## 语法 -`INT years_diff(DATETIME enddate, DATETIME startdate)` +```sql +YEARS_DIFF(<enddate>, <startdate>) +``` + +## 参数 + +| 参数 | 说明 | +| ---- | ---- | +| `<enddate>` | 结束日期,类型为 DATETIME 或 DATE | +| `<startdate>` | 开始日期,类型为 DATETIME 或 DATE | -开始时间到结束时间相差几年 +## 返回值 + +返回类型为 INT,表示两个日期之间相差的年数。 ## 举例 +```sql +SELECT YEARS_DIFF('2020-12-25', '2019-10-25'); ``` -mysql> select years_diff('2020-12-25','2019-10-25'); + +```text +----------------------------------------------------------+ | years_diff('2020-12-25 00:00:00', '2019-10-25 00:00:00') | +----------------------------------------------------------+ | 1 | +----------------------------------------------------------+ ``` - -### keywords - - years_diff diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/years-sub.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/years-sub.md index 7c05bc24762..bd42896c9af 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/years-sub.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/years-sub.md @@ -24,27 +24,37 @@ specific language governing permissions and limitations under the License. --> -## years_sub ## 描述 + +返回一个新的日期时间值,该值是从输入的日期时间中减去指定的年数。 + ## 语法 -`DATETIME YEARS_SUB(DATETIME date, INT years)` +```sql +YEARS_SUB(<date>, <years>) +``` + +## 参数 -从日期时间或日期减去指定年数 +| 参数 | 说明 | +| ---- | ---- | +| `<date>` | 输入的日期时间值,类型为 DATETIME 或 DATE | +| `<years>` | 要减去的年数,类型为 INT | -参数 date 可以是 DATETIME 或者 DATE 类型,返回类型与参数 date 的类型一致。 +## 返回值 + +返回与输入 `<date>` 类型相同的值(DATETIME 或 DATE),表示从输入日期时间中减去指定年数后的时间值。 ## 举例 +```sql +SELECT YEARS_SUB('2020-02-02 02:02:02', 1); ``` -mysql> select years_sub("2020-02-02 02:02:02", 1); + +```text +-------------------------------------+ | years_sub('2020-02-02 02:02:02', 1) | +-------------------------------------+ | 2019-02-02 02:02:02 | +-------------------------------------+ ``` - -### keywords - - YEARS_SUB diff --git a/versioned_docs/version-2.0/sql-manual/sql-functions/date-time-functions/years-add.md b/versioned_docs/version-2.0/sql-manual/sql-functions/date-time-functions/years-add.md index 7b9a7cc5b91..1a72b332964 100644 --- a/versioned_docs/version-2.0/sql-manual/sql-functions/date-time-functions/years-add.md +++ b/versioned_docs/version-2.0/sql-manual/sql-functions/date-time-functions/years-add.md @@ -24,27 +24,37 @@ specific language governing permissions and limitations under the License. --> -## years_add -### description -#### Syntax +## Description -`DATETIME YEARS_ADD(DATETIME date, INT years)` +Returns a new datetime value that is the result of adding a specified number of years to the input datetime. -ADD a specified number of years from a datetime or date +## Syntax -The parameter date can be DATETIME or DATE, and the return type is consistent with that of the parameter date. +```sql +YEARS_ADD(<date>, <years>) +``` + +## Parameters + +| Parameter | Description | +|-----------|--------------------------------------------------| +| `<date>` | The input datetime value, which can be of type DATETIME or DATE | +| `<years>` | The number of years to add, of type INT | + +## Return Value -### example +Returns a value with the same type as the input `<date>` (DATETIME or DATE), representing the time value after adding the specified number of years to the input datetime. +## Example + +```sql +SELECT YEARS_ADD('2020-01-31 02:02:02', 1); ``` -mysql> select years_add("2020-01-31 02:02:02", 1); + +```text +-------------------------------------+ | years_add('2020-01-31 02:02:02', 1) | +-------------------------------------+ | 2021-01-31 02:02:02 | +-------------------------------------+ ``` - -### keywords - - YEARS_ADD diff --git a/versioned_docs/version-2.0/sql-manual/sql-functions/date-time-functions/years-diff.md b/versioned_docs/version-2.0/sql-manual/sql-functions/date-time-functions/years-diff.md index bb787b64096..da87f045dee 100644 --- a/versioned_docs/version-2.0/sql-manual/sql-functions/date-time-functions/years-diff.md +++ b/versioned_docs/version-2.0/sql-manual/sql-functions/date-time-functions/years-diff.md @@ -24,25 +24,37 @@ specific language governing permissions and limitations under the License. --> -## years_diff -### description -#### Syntax +## Description -`INT years_diff(DATETIME enddate, DATETIME startdate)` +Calculates the difference in years between two datetime values. -The difference between the start time and the end time is several years +## Syntax -### example +```sql +YEARS_DIFF(<enddate>, <startdate>) +``` + +## Parameters + +| Parameter | Description | +|-----------|--------------------------------------------------| +| `<enddate>` | The end date, which can be of type DATETIME or DATE | +| `<startdate>` | The start date, which can be of type DATETIME or DATE | + +## Return Value + +Returns a value of type INT, representing the number of years between the two dates. +## Example + +```sql +SELECT YEARS_DIFF('2020-12-25', '2019-10-25'); ``` -mysql> select years_diff('2020-12-25','2019-10-25'); + +```text +----------------------------------------------------------+ | years_diff('2020-12-25 00:00:00', '2019-10-25 00:00:00') | +----------------------------------------------------------+ | 1 | +----------------------------------------------------------+ ``` - -### keywords - - years_diff diff --git a/versioned_docs/version-2.0/sql-manual/sql-functions/date-time-functions/years-sub.md b/versioned_docs/version-2.0/sql-manual/sql-functions/date-time-functions/years-sub.md index 7cd68cf4a7a..cc6c940f6e5 100644 --- a/versioned_docs/version-2.0/sql-manual/sql-functions/date-time-functions/years-sub.md +++ b/versioned_docs/version-2.0/sql-manual/sql-functions/date-time-functions/years-sub.md @@ -24,27 +24,37 @@ specific language governing permissions and limitations under the License. --> -## years_sub -### description -#### Syntax +## Description -`DATETIME YEARS_SUB(DATETIME date, INT years)` +Returns a new datetime value that is the result of subtracting a specified number of years from the input datetime. -Subtracts a specified number of years from a datetime or date +## Syntax -The parameter date can be DATETIME or DATE, and the return type is consistent with that of the parameter date. +```sql +YEARS_SUB(<date>, <years>) +``` + +## Parameters + +| Parameter | Description | +|-----------|--------------------------------------------------| +| `<date>` | The input datetime value, which can be of type DATETIME or DATE | +| `<years>` | The number of years to subtract, of type INT | + +## Return Value -### example +Returns a value with the same type as the input `<date>` (DATETIME or DATE), representing the time value after subtracting the specified number of years from the input datetime. +## Example + +```sql +SELECT YEARS_SUB('2020-02-02 02:02:02', 1); ``` -mysql> select years_sub("2020-02-02 02:02:02", 1); + +```text +-------------------------------------+ | years_sub('2020-02-02 02:02:02', 1) | +-------------------------------------+ | 2019-02-02 02:02:02 | +-------------------------------------+ ``` - -### keywords - - YEARS_SUB diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestamp.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestamp.md index 0fd806b9080..ad04082cfb4 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestamp.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestamp.md @@ -23,3 +23,57 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> + +## Description + +The TIMESTAMP function has two uses: + +1. Convert a datetime string to a DATETIME type +2. Combine two arguments into a DATETIME type + +## Syntax + +```sql +TIMESTAMP(string) +TIMESTAMP(date, time) +``` + +## Parameters + +| Parameter | Description | +|-----------|--------------------------------------------------| +| `string` | A datetime string | +| `date` | A date value, which can be a DATE type or a properly formatted date string | +| `time` | A time value, which can be a TIME type or a properly formatted time string | + +## Return Value + +Returns a value of type DATETIME. + +## Example + +```sql +-- Convert a string to DATETIME +SELECT TIMESTAMP('2019-01-01 12:00:00'); +``` + +```text ++------------------------------------+ +| timestamp('2019-01-01 12:00:00') | ++------------------------------------+ +| 2019-01-01 12:00:00 | ++------------------------------------+ +``` + +```sql +-- Combine date and time into DATETIME +SELECT TIMESTAMP('2019-01-01', '12:00:00'); +``` + +```text ++----------------------------------------+ +| timestamp('2019-01-01', '12:00:00') | ++----------------------------------------+ +| 2019-01-01 12:00:00 | ++----------------------------------------+ +``` diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/to-iso8601.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/to-iso8601.md index 8d8148f04e8..905f2fcb253 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/to-iso8601.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/to-iso8601.md @@ -23,3 +23,37 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> + +## Description + +Converts a datetime value to an ISO8601 formatted string. + +## Syntax + +```sql +TO_ISO8601(<dt>) +``` + +## Parameters + +| Parameter | Description | +|-----------|--------------------------------------------------| +| `<dt>` | The input datetime value, which can be of type DATETIME or DATE | + +## Return Value + +Returns a value of type VARCHAR, representing the datetime in ISO8601 format. + +## Example + +```sql +SELECT TO_ISO8601('2020-01-01 12:30:45'); +``` + +```text ++-------------------------------------+ +| to_iso8601('2020-01-01 12:30:45.0') | ++-------------------------------------+ +| 2020-01-01T12:30:45 | ++-------------------------------------+ +``` diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/week-ceil.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/week-ceil.md index 26abc3cce19..267160f350d 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/week-ceil.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/week-ceil.md @@ -23,3 +23,48 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> + +## Description + +Rounds up a datetime value to the nearest specified week interval. If a starting time (origin) is provided, it uses that time as the reference for calculating the interval. + +## Syntax + +```sql +WEEK_CEIL(<datetime>) +WEEK_CEIL(<datetime>, <origin>) +WEEK_CEIL(<datetime>, <period>) +WEEK_CEIL(<datetime>, <period>, <origin>) +``` + +## Parameters + +| Parameter | Description | +|-----------|--------------------------------------------------| +| `<datetime>` | The datetime value to round up, of type DATETIME or DATETIMEV2 | +| `<period>` | The week interval value, of type INT, representing the number of weeks in each interval | +| `<origin>` | The starting point for the interval, of type DATETIME or DATETIMEV2; defaults to 0001-01-01 00:00:00 | + +## Return Value + +Returns a value of type DATETIME, representing the rounded-up datetime value. The time portion of the result will be set to 00:00:00. + +**Note:** +- If no period is specified, it defaults to a 1-week interval. +- The period must be a positive integer. +- The result is always rounded up to a future time. +- The time portion of the returned value is always set to 00:00:00. + +## Example + +```sql +SELECT WEEK_CEIL('2023-07-13 22:28:18', 2); +``` + +```text ++-----------------------------------------------------------+ +| week_ceil(cast('2023-07-13 22:28:18' as DATETIMEV2(0)), 2) | ++-----------------------------------------------------------+ +| 2023-07-17 00:00:00 | ++-----------------------------------------------------------+ +``` diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/week-floor.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/week-floor.md index d02e4cc1e5d..ddf255f6b39 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/week-floor.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/week-floor.md @@ -23,3 +23,48 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> + +## Description + +Rounds down a datetime value to the nearest specified week interval. If a starting time (origin) is provided, it uses that time as the reference for calculating the interval. + +## Syntax + +```sql +WEEK_FLOOR(<datetime>) +WEEK_FLOOR(<datetime>, <origin>) +WEEK_FLOOR(<datetime>, <period>) +WEEK_FLOOR(<datetime>, <period>, <origin>) +``` + +## Parameters + +| Parameter | Description | +|-----------|--------------------------------------------------| +| `<datetime>` | The datetime value to round down, of type DATETIME or DATETIMEV2 | +| `<period>` | The week interval value, of type INT, representing the number of weeks in each interval | +| `<origin>` | The starting point for the interval, of type DATETIME or DATETIMEV2; defaults to 0001-01-01 00:00:00 | + +## Return Value + +Returns a value of type DATETIME, representing the rounded-down datetime value. The time portion of the result will be set to 00:00:00. + +**Note:** +- If no period is specified, it defaults to a 1-week interval. +- The period must be a positive integer. +- The result is always rounded down to a past time. +- The time portion of the returned value is always set to 00:00:00. + +## Example + +```sql +SELECT WEEK_FLOOR('2023-07-13 22:28:18', 2); +``` + +```text ++------------------------------------------------------------+ +| week_floor(cast('2023-07-13 22:28:18' as DATETIMEV2(0)), 2) | ++------------------------------------------------------------+ +| 2023-07-03 00:00:00 | ++------------------------------------------------------------+ +``` diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/years-add.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/years-add.md index 7b9a7cc5b91..1a72b332964 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/years-add.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/years-add.md @@ -24,27 +24,37 @@ specific language governing permissions and limitations under the License. --> -## years_add -### description -#### Syntax +## Description -`DATETIME YEARS_ADD(DATETIME date, INT years)` +Returns a new datetime value that is the result of adding a specified number of years to the input datetime. -ADD a specified number of years from a datetime or date +## Syntax -The parameter date can be DATETIME or DATE, and the return type is consistent with that of the parameter date. +```sql +YEARS_ADD(<date>, <years>) +``` + +## Parameters + +| Parameter | Description | +|-----------|--------------------------------------------------| +| `<date>` | The input datetime value, which can be of type DATETIME or DATE | +| `<years>` | The number of years to add, of type INT | + +## Return Value -### example +Returns a value with the same type as the input `<date>` (DATETIME or DATE), representing the time value after adding the specified number of years to the input datetime. +## Example + +```sql +SELECT YEARS_ADD('2020-01-31 02:02:02', 1); ``` -mysql> select years_add("2020-01-31 02:02:02", 1); + +```text +-------------------------------------+ | years_add('2020-01-31 02:02:02', 1) | +-------------------------------------+ | 2021-01-31 02:02:02 | +-------------------------------------+ ``` - -### keywords - - YEARS_ADD diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/years-diff.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/years-diff.md index bb787b64096..da87f045dee 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/years-diff.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/years-diff.md @@ -24,25 +24,37 @@ specific language governing permissions and limitations under the License. --> -## years_diff -### description -#### Syntax +## Description -`INT years_diff(DATETIME enddate, DATETIME startdate)` +Calculates the difference in years between two datetime values. -The difference between the start time and the end time is several years +## Syntax -### example +```sql +YEARS_DIFF(<enddate>, <startdate>) +``` + +## Parameters + +| Parameter | Description | +|-----------|--------------------------------------------------| +| `<enddate>` | The end date, which can be of type DATETIME or DATE | +| `<startdate>` | The start date, which can be of type DATETIME or DATE | + +## Return Value + +Returns a value of type INT, representing the number of years between the two dates. +## Example + +```sql +SELECT YEARS_DIFF('2020-12-25', '2019-10-25'); ``` -mysql> select years_diff('2020-12-25','2019-10-25'); + +```text +----------------------------------------------------------+ | years_diff('2020-12-25 00:00:00', '2019-10-25 00:00:00') | +----------------------------------------------------------+ | 1 | +----------------------------------------------------------+ ``` - -### keywords - - years_diff diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/years-sub.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/years-sub.md index 7cd68cf4a7a..cc6c940f6e5 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/years-sub.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/years-sub.md @@ -24,27 +24,37 @@ specific language governing permissions and limitations under the License. --> -## years_sub -### description -#### Syntax +## Description -`DATETIME YEARS_SUB(DATETIME date, INT years)` +Returns a new datetime value that is the result of subtracting a specified number of years from the input datetime. -Subtracts a specified number of years from a datetime or date +## Syntax -The parameter date can be DATETIME or DATE, and the return type is consistent with that of the parameter date. +```sql +YEARS_SUB(<date>, <years>) +``` + +## Parameters + +| Parameter | Description | +|-----------|--------------------------------------------------| +| `<date>` | The input datetime value, which can be of type DATETIME or DATE | +| `<years>` | The number of years to subtract, of type INT | + +## Return Value -### example +Returns a value with the same type as the input `<date>` (DATETIME or DATE), representing the time value after subtracting the specified number of years from the input datetime. +## Example + +```sql +SELECT YEARS_SUB('2020-02-02 02:02:02', 1); ``` -mysql> select years_sub("2020-02-02 02:02:02", 1); + +```text +-------------------------------------+ | years_sub('2020-02-02 02:02:02', 1) | +-------------------------------------+ | 2019-02-02 02:02:02 | +-------------------------------------+ ``` - -### keywords - - YEARS_SUB diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/string-functions/timestamp.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/string-functions/timestamp.md deleted file mode 100644 index 1c0fb28318a..00000000000 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/string-functions/timestamp.md +++ /dev/null @@ -1,25 +0,0 @@ ---- -{ - "title": "TIMESTAMP", - "language": "zh-CN" -} ---- - -<!-- -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. ---> diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestamp.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestamp.md index 0fd806b9080..ad04082cfb4 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestamp.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestamp.md @@ -23,3 +23,57 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> + +## Description + +The TIMESTAMP function has two uses: + +1. Convert a datetime string to a DATETIME type +2. Combine two arguments into a DATETIME type + +## Syntax + +```sql +TIMESTAMP(string) +TIMESTAMP(date, time) +``` + +## Parameters + +| Parameter | Description | +|-----------|--------------------------------------------------| +| `string` | A datetime string | +| `date` | A date value, which can be a DATE type or a properly formatted date string | +| `time` | A time value, which can be a TIME type or a properly formatted time string | + +## Return Value + +Returns a value of type DATETIME. + +## Example + +```sql +-- Convert a string to DATETIME +SELECT TIMESTAMP('2019-01-01 12:00:00'); +``` + +```text ++------------------------------------+ +| timestamp('2019-01-01 12:00:00') | ++------------------------------------+ +| 2019-01-01 12:00:00 | ++------------------------------------+ +``` + +```sql +-- Combine date and time into DATETIME +SELECT TIMESTAMP('2019-01-01', '12:00:00'); +``` + +```text ++----------------------------------------+ +| timestamp('2019-01-01', '12:00:00') | ++----------------------------------------+ +| 2019-01-01 12:00:00 | ++----------------------------------------+ +``` diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/to-iso8601.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/to-iso8601.md index 8d8148f04e8..905f2fcb253 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/to-iso8601.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/to-iso8601.md @@ -23,3 +23,37 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> + +## Description + +Converts a datetime value to an ISO8601 formatted string. + +## Syntax + +```sql +TO_ISO8601(<dt>) +``` + +## Parameters + +| Parameter | Description | +|-----------|--------------------------------------------------| +| `<dt>` | The input datetime value, which can be of type DATETIME or DATE | + +## Return Value + +Returns a value of type VARCHAR, representing the datetime in ISO8601 format. + +## Example + +```sql +SELECT TO_ISO8601('2020-01-01 12:30:45'); +``` + +```text ++-------------------------------------+ +| to_iso8601('2020-01-01 12:30:45.0') | ++-------------------------------------+ +| 2020-01-01T12:30:45 | ++-------------------------------------+ +``` diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/week-ceil.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/week-ceil.md index 26abc3cce19..267160f350d 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/week-ceil.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/week-ceil.md @@ -23,3 +23,48 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> + +## Description + +Rounds up a datetime value to the nearest specified week interval. If a starting time (origin) is provided, it uses that time as the reference for calculating the interval. + +## Syntax + +```sql +WEEK_CEIL(<datetime>) +WEEK_CEIL(<datetime>, <origin>) +WEEK_CEIL(<datetime>, <period>) +WEEK_CEIL(<datetime>, <period>, <origin>) +``` + +## Parameters + +| Parameter | Description | +|-----------|--------------------------------------------------| +| `<datetime>` | The datetime value to round up, of type DATETIME or DATETIMEV2 | +| `<period>` | The week interval value, of type INT, representing the number of weeks in each interval | +| `<origin>` | The starting point for the interval, of type DATETIME or DATETIMEV2; defaults to 0001-01-01 00:00:00 | + +## Return Value + +Returns a value of type DATETIME, representing the rounded-up datetime value. The time portion of the result will be set to 00:00:00. + +**Note:** +- If no period is specified, it defaults to a 1-week interval. +- The period must be a positive integer. +- The result is always rounded up to a future time. +- The time portion of the returned value is always set to 00:00:00. + +## Example + +```sql +SELECT WEEK_CEIL('2023-07-13 22:28:18', 2); +``` + +```text ++-----------------------------------------------------------+ +| week_ceil(cast('2023-07-13 22:28:18' as DATETIMEV2(0)), 2) | ++-----------------------------------------------------------+ +| 2023-07-17 00:00:00 | ++-----------------------------------------------------------+ +``` diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/week-floor.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/week-floor.md index d02e4cc1e5d..ddf255f6b39 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/week-floor.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/week-floor.md @@ -23,3 +23,48 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> + +## Description + +Rounds down a datetime value to the nearest specified week interval. If a starting time (origin) is provided, it uses that time as the reference for calculating the interval. + +## Syntax + +```sql +WEEK_FLOOR(<datetime>) +WEEK_FLOOR(<datetime>, <origin>) +WEEK_FLOOR(<datetime>, <period>) +WEEK_FLOOR(<datetime>, <period>, <origin>) +``` + +## Parameters + +| Parameter | Description | +|-----------|--------------------------------------------------| +| `<datetime>` | The datetime value to round down, of type DATETIME or DATETIMEV2 | +| `<period>` | The week interval value, of type INT, representing the number of weeks in each interval | +| `<origin>` | The starting point for the interval, of type DATETIME or DATETIMEV2; defaults to 0001-01-01 00:00:00 | + +## Return Value + +Returns a value of type DATETIME, representing the rounded-down datetime value. The time portion of the result will be set to 00:00:00. + +**Note:** +- If no period is specified, it defaults to a 1-week interval. +- The period must be a positive integer. +- The result is always rounded down to a past time. +- The time portion of the returned value is always set to 00:00:00. + +## Example + +```sql +SELECT WEEK_FLOOR('2023-07-13 22:28:18', 2); +``` + +```text ++------------------------------------------------------------+ +| week_floor(cast('2023-07-13 22:28:18' as DATETIMEV2(0)), 2) | ++------------------------------------------------------------+ +| 2023-07-03 00:00:00 | ++------------------------------------------------------------+ +``` diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/years-add.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/years-add.md index 7b9a7cc5b91..1a72b332964 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/years-add.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/years-add.md @@ -24,27 +24,37 @@ specific language governing permissions and limitations under the License. --> -## years_add -### description -#### Syntax +## Description -`DATETIME YEARS_ADD(DATETIME date, INT years)` +Returns a new datetime value that is the result of adding a specified number of years to the input datetime. -ADD a specified number of years from a datetime or date +## Syntax -The parameter date can be DATETIME or DATE, and the return type is consistent with that of the parameter date. +```sql +YEARS_ADD(<date>, <years>) +``` + +## Parameters + +| Parameter | Description | +|-----------|--------------------------------------------------| +| `<date>` | The input datetime value, which can be of type DATETIME or DATE | +| `<years>` | The number of years to add, of type INT | + +## Return Value -### example +Returns a value with the same type as the input `<date>` (DATETIME or DATE), representing the time value after adding the specified number of years to the input datetime. +## Example + +```sql +SELECT YEARS_ADD('2020-01-31 02:02:02', 1); ``` -mysql> select years_add("2020-01-31 02:02:02", 1); + +```text +-------------------------------------+ | years_add('2020-01-31 02:02:02', 1) | +-------------------------------------+ | 2021-01-31 02:02:02 | +-------------------------------------+ ``` - -### keywords - - YEARS_ADD diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/years-diff.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/years-diff.md index bb787b64096..da87f045dee 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/years-diff.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/years-diff.md @@ -24,25 +24,37 @@ specific language governing permissions and limitations under the License. --> -## years_diff -### description -#### Syntax +## Description -`INT years_diff(DATETIME enddate, DATETIME startdate)` +Calculates the difference in years between two datetime values. -The difference between the start time and the end time is several years +## Syntax -### example +```sql +YEARS_DIFF(<enddate>, <startdate>) +``` + +## Parameters + +| Parameter | Description | +|-----------|--------------------------------------------------| +| `<enddate>` | The end date, which can be of type DATETIME or DATE | +| `<startdate>` | The start date, which can be of type DATETIME or DATE | + +## Return Value + +Returns a value of type INT, representing the number of years between the two dates. +## Example + +```sql +SELECT YEARS_DIFF('2020-12-25', '2019-10-25'); ``` -mysql> select years_diff('2020-12-25','2019-10-25'); + +```text +----------------------------------------------------------+ | years_diff('2020-12-25 00:00:00', '2019-10-25 00:00:00') | +----------------------------------------------------------+ | 1 | +----------------------------------------------------------+ ``` - -### keywords - - years_diff diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/years-sub.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/years-sub.md index 7cd68cf4a7a..cc6c940f6e5 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/years-sub.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/years-sub.md @@ -24,27 +24,37 @@ specific language governing permissions and limitations under the License. --> -## years_sub -### description -#### Syntax +## Description -`DATETIME YEARS_SUB(DATETIME date, INT years)` +Returns a new datetime value that is the result of subtracting a specified number of years from the input datetime. -Subtracts a specified number of years from a datetime or date +## Syntax -The parameter date can be DATETIME or DATE, and the return type is consistent with that of the parameter date. +```sql +YEARS_SUB(<date>, <years>) +``` + +## Parameters + +| Parameter | Description | +|-----------|--------------------------------------------------| +| `<date>` | The input datetime value, which can be of type DATETIME or DATE | +| `<years>` | The number of years to subtract, of type INT | + +## Return Value -### example +Returns a value with the same type as the input `<date>` (DATETIME or DATE), representing the time value after subtracting the specified number of years from the input datetime. +## Example + +```sql +SELECT YEARS_SUB('2020-02-02 02:02:02', 1); ``` -mysql> select years_sub("2020-02-02 02:02:02", 1); + +```text +-------------------------------------+ | years_sub('2020-02-02 02:02:02', 1) | +-------------------------------------+ | 2019-02-02 02:02:02 | +-------------------------------------+ ``` - -### keywords - - YEARS_SUB diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/string-functions/timestamp.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/string-functions/timestamp.md deleted file mode 100644 index 1c0fb28318a..00000000000 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/string-functions/timestamp.md +++ /dev/null @@ -1,25 +0,0 @@ ---- -{ - "title": "TIMESTAMP", - "language": "zh-CN" -} ---- - -<!-- -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. ---> --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org