From e4677851779c1f44d29937af6d3f9fade121540e Mon Sep 17 00:00:00 2001 From: yuanyuan Date: Fri, 17 Jan 2025 20:26:46 +0800 Subject: [PATCH 1/2] date func --- .../date-time-functions/date-ceil.md | 84 ++++++++--------- .../date-time-functions/date-floor.md | 94 ++++++++++--------- .../date-time-functions/extract.md | 44 +++++---- .../date-time-functions/timestampadd.md | 38 +++++--- .../date-time-functions/timestampdiff.md | 51 ++++++---- .../date-time-functions/date-ceil.md | 78 +++++++-------- .../date-time-functions/date-floor.md | 90 +++++++++--------- .../date-time-functions/extract.md | 38 +++++--- .../date-time-functions/timestampadd.md | 31 +++--- .../date-time-functions/timestampdiff.md | 43 +++++---- .../date-time-functions/date-ceil.md | 78 +++++++-------- .../date-time-functions/date-floor.md | 90 +++++++++--------- .../date-time-functions/extract.md | 38 +++++--- .../date-time-functions/timestampadd.md | 31 +++--- .../date-time-functions/timestampdiff.md | 43 +++++---- .../date-time-functions/date-ceil.md | 78 +++++++-------- .../date-time-functions/date-floor.md | 90 +++++++++--------- .../date-time-functions/extract.md | 38 +++++--- .../date-time-functions/timestampadd.md | 31 +++--- .../date-time-functions/timestampdiff.md | 43 +++++---- .../date-time-functions/date-ceil.md | 84 ++++++++--------- .../date-time-functions/date-floor.md | 94 ++++++++++--------- .../date-time-functions/extract.md | 44 +++++---- .../date-time-functions/timestampadd.md | 38 +++++--- .../date-time-functions/timestampdiff.md | 51 ++++++---- .../date-time-functions/date-ceil.md | 84 ++++++++--------- .../date-time-functions/date-floor.md | 94 ++++++++++--------- .../date-time-functions/extract.md | 44 +++++---- .../date-time-functions/timestampadd.md | 38 +++++--- .../date-time-functions/timestampdiff.md | 51 ++++++---- 30 files changed, 990 insertions(+), 783 deletions(-) diff --git a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md index c5971bed2f15b..d59f6e7d6978b 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md +++ b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md @@ -1,6 +1,6 @@ --- { - "title": "date_ceil", + "title": "DATE_CEIL", "language": "en" } --- @@ -24,83 +24,83 @@ specific language governing permissions and limitations under the License. --> -## date_ceil -### Description -**Syntax** +## Description -`DATETIME DATE_CEIL(DATETIME datetime, INTERVAL period type)` +`date_ceil` rounds a given date to the next upper boundary of the specified time interval. +## Syntax -Convert the date to the nearest rounding up time of the specified time interval period. +`DATE_CEIL(DATETIME datetime, INTERVAL period type)` -The datetime parameter is a valid date expression. +## Parameters -The period parameter specifies how many units each cycle consists of, starting from 0001-01-01T00:00:00 +| Parameter | Description | +| -- | -- | +| `datetime` | The argument is a valid date expression | +| `period` | The argument specifies how many units make up each period, with the start time being 0001-01-01T00:00:00 | +| `type` | The argument can be: YEAR, MONTH, DAY, HOUR, MINUTE, SECOND| -Type: YEAR, MONTH, DAY, HOUR, MINUTE, SECOND. +## Return Value -### Example +The return value is a date or time, representing the result of rounding the input value up to the specified unit. +## Examples + +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 second); ``` -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 second); +```text +--------------------------------------------------------------+ | second_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +--------------------------------------------------------------+ | 2023-07-13 22:28:20 | +--------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 minute); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 minute); +--------------------------------------------------------------+ | minute_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +--------------------------------------------------------------+ | 2023-07-13 22:30:00 | +--------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 hour); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 hour); +``` +```text +------------------------------------------------------------+ | hour_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +------------------------------------------------------------+ | 2023-07-13 23:00:00 | +------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 day); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 day); +``` +```text +-----------------------------------------------------------+ | day_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +-----------------------------------------------------------+ | 2023-07-15 00:00:00 | +-----------------------------------------------------------+ -1 row in set (0.00 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 month); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 month); +``` +```text +-------------------------------------------------------------+ | month_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +-------------------------------------------------------------+ | 2023-12-01 00:00:00 | +-------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 year); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 year); +``` +```text +------------------------------------------------------------+ | year_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +------------------------------------------------------------+ | 2026-01-01 00:00:00 | +------------------------------------------------------------+ -1 row in set (0.00 sec) -``` - -### Keywords - - DATE_CEIL,DATE,CEIL - -### Best Practices - -See also -- [second_ceil](./second_ceil) -- [minute_ceil](./minute_ceil) -- [hour_ceil](./hour_ceil) -- [day_ceil](./day_ceil) -- [month_ceil](./month_ceil) -- [year_ceil](./year_ceil) +``` \ No newline at end of file diff --git a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md index 565c72439be4f..3841898e3d4d2 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md +++ b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md @@ -1,6 +1,6 @@ --- { - "title": "date_floor", + "title": "DATE_FLOOR", "language": "en" } --- @@ -24,91 +24,95 @@ specific language governing permissions and limitations under the License. --> -## date_floor -### Description -**Syntax** +## Description -`DATETIME DATE_FLOOR(DATETIME datetime, INTERVAL period type)` +`date_floor` rounds a given date to the closest lower boundary of the specified time interval. +## Syntax -Converts a date to the nearest rounding down time of a specified time interval period. +`DATE_FLOOR(DATETIME datetime, INTERVAL period type)` -The datetime parameter is a valid date expression. +## Parameters -The period parameter specifies how many units each cycle consists of, starting from 0001-01-01T00:00:00 +| Parameter | Description | +| -- | -- | +| `datetime` | The argument is a valid date expression | +| `period` | The argument specifies how many units make up each period, with the start time being 0001-01-01T00:00:00 | +| `type` | The argument can be: YEAR, MONTH, DAY, HOUR, MINUTE, SECOND| -Type: YEAR, MONTH, DAY, HOUR, MINUTE, SECOND. +## Return Value -### Example +The return value is a date or time, representing the result of rounding the input value down to the specified unit. +## Examples + +```sql +select date_floor("0001-01-01 00:00:16",interval 5 second); ``` -mysql>select date_floor("0001-01-01 00:00:16",interval 5 second); +```text +---------------------------------------------------------------+ | second_floor('0001-01-01 00:00:16', 5, '0001-01-01 00:00:00') | +---------------------------------------------------------------+ | 0001-01-01 00:00:15 | +---------------------------------------------------------------+ -1 row in set (0.00 sec) - -mysql>select date_floor("0001-01-01 00:00:18",interval 5 second); +``` +```sql +select date_floor("0001-01-01 00:00:18",interval 5 second); +``` +```text +---------------------------------------------------------------+ | second_floor('0001-01-01 00:00:18', 5, '0001-01-01 00:00:00') | +---------------------------------------------------------------+ | 0001-01-01 00:00:15 | +---------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 minute); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 minute); +``` +```text +---------------------------------------------------------------+ | minute_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +---------------------------------------------------------------+ | 2023-07-13 22:25:00 | +---------------------------------------------------------------+ -1 row in set (0.00 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 hour); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 hour); +``` +```text +-------------------------------------------------------------+ | hour_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +-------------------------------------------------------------+ | 2023-07-13 18:00:00 | +-------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 day); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 day); +``` +```text +------------------------------------------------------------+ | day_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +------------------------------------------------------------+ | 2023-07-10 00:00:00 | +------------------------------------------------------------+ -1 row in set (0.00 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 month); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 month); +``` +```text +--------------------------------------------------------------+ | month_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +--------------------------------------------------------------+ | 2023-07-01 00:00:00 | +--------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 year); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 year); +``` +```text +-------------------------------------------------------------+ | year_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +-------------------------------------------------------------+ | 2021-01-01 00:00:00 | +-------------------------------------------------------------+ - -``` - -### Keywords - - DATE_FLOOR,DATE,FLOOR - -### Best Practices - -See also -- [second_floor](./second_floor) -- [minute_floor](./minute_floor) -- [hour_floor](./hour_floor) -- [day_floor](./day_floor) -- [month_floor](./month_floor) -- [year_floor](./year_floor) +``` \ No newline at end of file diff --git a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md index 19e2f9a271fe9..8c17aca87b305 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md +++ b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md @@ -24,31 +24,41 @@ specific language governing permissions and limitations under the License. --> -## extract -### description -#### Syntax +## Description -`INT extract(unit FROM DATETIME)` +The `extract` function is used to extract a specified part of a date or time value, such as the year, month, day, hour, minute, second, etc. This function is commonly used to extract specific time components from a datetime field for calculation, comparison, or display. -Extract DATETIME The value of a specified unit. The unit can be year, day, hour, minute, second or microsecond +## Syntax -### Example +`EXTRACT(unit FROM DATETIME)` +## Parameters + +| Parameter | Description | +| -- | -- | +| `unit` | The unit to extract from the DATETIME. Possible values are year, month, day, hour, minute, second, or microsecond | +| `from` | Fixed syntax | +| `period` | The argument is a valid date expression | + +## Return Value + +The return value is the extracted part of the date or time (such as an integer), depending on the unit being extracted. + +## Examples + +```sql +select extract(year from '2022-09-22 17:01:30') as year, +extract(month from '2022-09-22 17:01:30') as month, +extract(day from '2022-09-22 17:01:30') as day, +extract(hour from '2022-09-22 17:01:30') as hour, +extract(minute from '2022-09-22 17:01:30') as minute, +extract(second from '2022-09-22 17:01:30') as second, +extract(microsecond from cast('2022-09-22 17:01:30.000123' as datetimev2(6))) as microsecond; ``` -mysql> select extract(year from '2022-09-22 17:01:30') as year, - -> extract(month from '2022-09-22 17:01:30') as month, - -> extract(day from '2022-09-22 17:01:30') as day, - -> extract(hour from '2022-09-22 17:01:30') as hour, - -> extract(minute from '2022-09-22 17:01:30') as minute, - -> extract(second from '2022-09-22 17:01:30') as second, - -> extract(microsecond from cast('2022-09-22 17:01:30.000123' as datetimev2(6))) as microsecond; +```text +------+-------+------+------+--------+--------+-------------+ | year | month | day | hour | minute | second | microsecond | +------+-------+------+------+--------+--------+-------------+ | 2022 | 9 | 22 | 17 | 1 | 30 | 123 | +------+-------+------+------+--------+--------+-------------+ ``` - -### keywords - - extract diff --git a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md index 2d97cb0824776..3b9f5f09b2ac5 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md +++ b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md @@ -24,35 +24,45 @@ specific language governing permissions and limitations under the License. --> -## timestampadd -### description -#### Syntax +## Description -`DATETIME TIMESTAMPADD(unit, interval, DATETIME datetime_expr)` +The `timestampadd` function is used to add a specified time unit (such as year, month, day, hour, minute, second, etc.) to a timestamp or date. This function is commonly used for date and time calculations. -Adds the integer expression interval to the date or datetime expression datetime_expr. +## Syntax -The unit for interval is given by the unit argument, which should be one of the following values: +`TIMESTAMPADD(unit, interval, DATETIME datetime_expr)` -SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, or YEAR. +## Parameters -### example +| Parameter | Description | +| -- | -- | +| `unit` | Time unit, specifies the time unit to add, common values include SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR | +| `interval` | The time interval to add, typically an integer, which can be positive or negative to add or subtract the time length | +| `DATETIME datetime_expr` | A valid target timestamp or date | -``` +## Return Value + +The return value is the new date and time, representing the result of adding or subtracting the specified time interval to the given timestamp. -mysql> SELECT TIMESTAMPADD(MINUTE,1,'2019-01-02'); +## Examples + +```sql +SELECT TIMESTAMPADD(MINUTE,1,'2019-01-02'); +``` +```text +------------------------------------------------+ | timestampadd(MINUTE, 1, '2019-01-02 00:00:00') | +------------------------------------------------+ | 2019-01-02 00:01:00 | +------------------------------------------------+ - -mysql> SELECT TIMESTAMPADD(WEEK,1,'2019-01-02'); +``` +```sql +SELECT TIMESTAMPADD(WEEK,1,'2019-01-02'); +``` +```text +----------------------------------------------+ | timestampadd(WEEK, 1, '2019-01-02 00:00:00') | +----------------------------------------------+ | 2019-01-09 00:00:00 | +----------------------------------------------+ ``` -### keywords - TIMESTAMPADD diff --git a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md index dd5769852d555..07aa4f6d8d172 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md +++ b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md @@ -24,44 +24,55 @@ specific language governing permissions and limitations under the License. --> -## timestampdiff -### description -#### Syntax +## Description -`INT TIMESTAMPDIFF(unit, DATETIME datetime_expr1, DATETIME datetime_expr2)` +The `timestampdiff` function is used to calculate the difference between two timestamps or dates and returns the time interval between them. The difference can be returned in the specified time unit (such as seconds, minutes, hours, days, months, years, etc.). -Returns datetime_expr2 − datetime_expr1, where datetime_expr1 and datetime_expr2 are date or datetime expressions. +## Syntax -The unit for the result (an integer) is given by the unit argument. - -The legal values for unit are the same as those listed in the description of the TIMESTAMPADD() function. +`TIMESTAMPDIFF(unit, DATETIME datetime_expr1, DATETIME datetime_expr2)` -### example +## Parameters -``` +| Parameter | Description | +| -- | -- | +| `unit` | Time unit, specifies the unit in which to return the difference, common values include SECOND, MINUTE, HOUR, DAY, MONTH, YEAR | +| `DATETIME datetime_expr1` | The first datetime, a valid target timestamp or date | +| `DATETIME datetime_expr2` | The second datetime, a valid target timestamp or date | + +## Return Value + +The return value is the difference between the two date-times, with the unit determined by the unit parameter. + +## Examples -MySQL> SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'); +```sql +SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'); +``` +```text +--------------------------------------------------------------------+ | timestampdiff(MONTH, '2003-02-01 00:00:00', '2003-05-01 00:00:00') | +--------------------------------------------------------------------+ | 3 | +--------------------------------------------------------------------+ - -MySQL> SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01'); +``` +```sql +SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01'); +``` +```text +-------------------------------------------------------------------+ | timestampdiff(YEAR, '2002-05-01 00:00:00', '2001-01-01 00:00:00') | +-------------------------------------------------------------------+ | -1 | +-------------------------------------------------------------------+ - - -MySQL> SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55'); +``` +```sql +SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55'); +``` +```text +---------------------------------------------------------------------+ | timestampdiff(MINUTE, '2003-02-01 00:00:00', '2003-05-01 12:05:55') | +---------------------------------------------------------------------+ | 128885 | +---------------------------------------------------------------------+ - -``` -### keywords - TIMESTAMPDIFF +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md index 7dbc4146ad69d..df887d244b64c 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md @@ -1,6 +1,6 @@ --- { - "title": "date_ceil", + "title": "DATE_CEIL", "language": "zh-CN" } --- @@ -24,83 +24,83 @@ specific language governing permissions and limitations under the License. --> -## date_ceil ## 描述 -**Syntax** -`DATETIME DATE_CEIL(DATETIME datetime, INTERVAL period type)` +`date_ceil` 将日期转化为指定的时间间隔周期的最近上取整时刻。 +## 语法 -将日期转化为指定的时间间隔周期的最近上取整时刻。 +`DATE_CEIL(DATETIME datetime, INTERVAL period type)` -datetime 参数是合法的日期表达式。 +## 参数 -period 参数是指定每个周期有多少个单位组成,开始的时间起点为0001-01-01T00:00:00. +| 参数 | 说明 | +| -- | -- | +| `datetime` | 参数是合法的日期表达式 | +| `period` | 参数是指定每个周期有多少个单位组成,开始的时间起点为0001-01-01T00:00:00 | +| `type` | 参数可以是:YEAR, MONTH, DAY, HOUR, MINUTE, SECOND | -type 参数可以是下列值:YEAR, MONTH, DAY, HOUR, MINUTE, SECOND. +## 返回值 + +返回的是一个日期或时间值,表示将输入值向上舍入到指定单位的结果。 ## 举例 +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 second); ``` -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 second); +```text +--------------------------------------------------------------+ | second_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +--------------------------------------------------------------+ | 2023-07-13 22:28:20 | +--------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 minute); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 minute); +--------------------------------------------------------------+ | minute_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +--------------------------------------------------------------+ | 2023-07-13 22:30:00 | +--------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 hour); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 hour); +``` +```text +------------------------------------------------------------+ | hour_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +------------------------------------------------------------+ | 2023-07-13 23:00:00 | +------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 day); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 day); +``` +```text +-----------------------------------------------------------+ | day_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +-----------------------------------------------------------+ | 2023-07-15 00:00:00 | +-----------------------------------------------------------+ -1 row in set (0.00 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 month); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 month); +``` +```text +-------------------------------------------------------------+ | month_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +-------------------------------------------------------------+ | 2023-12-01 00:00:00 | +-------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 year); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 year); +``` +```text +------------------------------------------------------------+ | year_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +------------------------------------------------------------+ | 2026-01-01 00:00:00 | +------------------------------------------------------------+ -1 row in set (0.00 sec) ``` - -### Keywords - - DATE_CEIL,DATE,CEIL - -### Best Practices - -还可参阅: -- [second_ceil](./second_ceil) -- [minute_ceil](./minute_ceil) -- [hour_ceil](./hour_ceil) -- [day_ceil](./day_ceil) -- [month_ceil](./month_ceil) -- [year_ceil](./year_ceil) diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md index 0219a2406334c..291a32180abfa 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md @@ -1,6 +1,6 @@ --- { - "title": "date_floor", + "title": "DATE_FLOOR", "language": "zh-CN" } --- @@ -24,91 +24,95 @@ specific language governing permissions and limitations under the License. --> -## date_floor ## 描述 -## 语法 -`DATETIME DATE_FLOOR(DATETIME datetime, INTERVAL period type)` +`date_floor` 将日期转化为指定的时间间隔周期的最近下取整时刻。 + +## 语法 +`DATE_FLOOR(DATETIME datetime, INTERVAL period type)` -将日期转化为指定的时间间隔周期的最近下取整时刻。 +## 参数 -datetime 参数是合法的日期表达式。 +| 参数 | 说明 | +| -- | -- | +| `datetime` | 参数是合法的日期表达式 | +| `period` | 参数是指定每个周期有多少个单位组成,开始的时间起点为0001-01-01T00:00:00 | +| `type` | 参数可以是:YEAR, MONTH, DAY, HOUR, MINUTE, SECOND | -period 参数是指定每个周期有多少个单位组成,开始的时间起点为0001-01-01T00:00:00. +## 返回值 -type 参数可以是下列值:YEAR, MONTH, DAY, HOUR, MINUTE, SECOND. +返回的是一个日期或时间值,表示将输入值向下舍入到指定单位的结果。 ## 举例 +```sql +select date_floor("0001-01-01 00:00:16",interval 5 second); ``` -mysql>select date_floor("0001-01-01 00:00:16",interval 5 second); +```text +---------------------------------------------------------------+ | second_floor('0001-01-01 00:00:16', 5, '0001-01-01 00:00:00') | +---------------------------------------------------------------+ | 0001-01-01 00:00:15 | +---------------------------------------------------------------+ -1 row in set (0.00 sec) - -mysql>select date_floor("0001-01-01 00:00:18",interval 5 second); +``` +```sql +select date_floor("0001-01-01 00:00:18",interval 5 second); +``` +```text +---------------------------------------------------------------+ | second_floor('0001-01-01 00:00:18', 5, '0001-01-01 00:00:00') | +---------------------------------------------------------------+ | 0001-01-01 00:00:15 | +---------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 minute); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 minute); +``` +```text +---------------------------------------------------------------+ | minute_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +---------------------------------------------------------------+ | 2023-07-13 22:25:00 | +---------------------------------------------------------------+ -1 row in set (0.00 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 hour); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 hour); +``` +```text +-------------------------------------------------------------+ | hour_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +-------------------------------------------------------------+ | 2023-07-13 18:00:00 | +-------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 day); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 day); +``` +```text +------------------------------------------------------------+ | day_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +------------------------------------------------------------+ | 2023-07-10 00:00:00 | +------------------------------------------------------------+ -1 row in set (0.00 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 month); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 month); +``` +```text +--------------------------------------------------------------+ | month_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +--------------------------------------------------------------+ | 2023-07-01 00:00:00 | +--------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 year); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 year); +``` +```text +-------------------------------------------------------------+ | year_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +-------------------------------------------------------------+ | 2021-01-01 00:00:00 | +-------------------------------------------------------------+ - -``` - -### keywords - - DATE_FLOOR,DATE,FLOOR - -### Best Practice - -还可参阅: -- [second_ceil](./second_ceil) -- [minute_ceil](./minute_ceil) -- [hour_ceil](./hour_ceil) -- [day_ceil](./day_ceil) -- [month_ceil](./month_ceil) -- [year_ceil](./year_ceil) +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md index e2ee3efeb0990..5594fdcbf2ed9 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md @@ -24,31 +24,41 @@ specific language governing permissions and limitations under the License. --> -## extract ## 描述 + +`extract` 函数用于从日期或时间值中提取指定的部分,如年份、月份、日、小时、分钟、秒等。该函数常用于从日期时间字段中提取具体的时间组件进行计算、比较或展示。 + ## 语法 -`INT extract(unit FROM DATETIME)` +`EXTRACT(unit FROM DATETIME)` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `unit` | 提取DATETIME某个指定单位的值。单位可以为year, month, day, hour, minute, second 或者 microsecond | +|`from`| 固定语法 | +| `period` | 参数是合法的日期表达式 | -提取DATETIME某个指定单位的值。单位可以为year, month, day, hour, minute, second 或者 microsecond +## 返回值 + +返回的是提取出的日期或时间的某个部分(如整数),具体的部分取决于提取的单位。 ## 举例 +```sql +select extract(year from '2022-09-22 17:01:30') as year, +extract(month from '2022-09-22 17:01:30') as month, +extract(day from '2022-09-22 17:01:30') as day, +extract(hour from '2022-09-22 17:01:30') as hour, +extract(minute from '2022-09-22 17:01:30') as minute, +extract(second from '2022-09-22 17:01:30') as second, +extract(microsecond from cast('2022-09-22 17:01:30.000123' as datetimev2(6))) as microsecond; ``` -mysql> select extract(year from '2022-09-22 17:01:30') as year, - -> extract(month from '2022-09-22 17:01:30') as month, - -> extract(day from '2022-09-22 17:01:30') as day, - -> extract(hour from '2022-09-22 17:01:30') as hour, - -> extract(minute from '2022-09-22 17:01:30') as minute, - -> extract(second from '2022-09-22 17:01:30') as second, - -> extract(microsecond from cast('2022-09-22 17:01:30.000123' as datetimev2(6))) as microsecond; +```text +------+-------+------+------+--------+--------+-------------+ | year | month | day | hour | minute | second | microsecond | +------+-------+------+------+--------+--------+-------------+ | 2022 | 9 | 22 | 17 | 1 | 30 | 123 | +------+-------+------+------+--------+--------+-------------+ ``` - -### keywords - - extract diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md index e56f3dbdbe2be..8ebf0bc6440c8 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md @@ -24,36 +24,45 @@ specific language governing permissions and limitations under the License. --> -## timestampadd ## 描述 + +`timestampadd` 函数用于将指定的时间单位(如年、月、日、小时、分钟、秒等)添加到一个时间戳或日期上。这个函数通常用于日期和时间的计算。 + ## 语法 -`DATETIME TIMESTAMPADD(unit, interval, DATETIME datetime_expr)` +`TIMESTAMPADD(unit, interval, DATETIME datetime_expr)` +## 参数 -将整数表达式间隔添加到日期或日期时间表达式datetime_expr中。 +| 参数 | 说明 | +| -- | -- | +| `unit` | 时间单位,指定要添加的时间单位,常见的值有 SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR| +|`interval`| 要添加的时间间隔,通常是一个整数,可以是正数或负数,表示添加或减去的时间长度 | +| `DATETIME datetime_expr` | 合法的目标时间戳或日期 | -interval的单位由unit参数给出,它应该是下列值之一: +## 返回值 -SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, or YEAR。 +返回新的日期时间,表示在指定时间点上添加或减去指定时间间隔后的结果。 ## 举例 +```sql +SELECT TIMESTAMPADD(MINUTE,1,'2019-01-02'); ``` - -mysql> SELECT TIMESTAMPADD(MINUTE,1,'2019-01-02'); +```text +------------------------------------------------+ | timestampadd(MINUTE, 1, '2019-01-02 00:00:00') | +------------------------------------------------+ | 2019-01-02 00:01:00 | +------------------------------------------------+ - -mysql> SELECT TIMESTAMPADD(WEEK,1,'2019-01-02'); +``` +```sql +SELECT TIMESTAMPADD(WEEK,1,'2019-01-02'); +``` +```text +----------------------------------------------+ | timestampadd(WEEK, 1, '2019-01-02 00:00:00') | +----------------------------------------------+ | 2019-01-09 00:00:00 | +----------------------------------------------+ ``` -### keywords - TIMESTAMPADD diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md index 587c23a130ac3..5bab33559541d 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md @@ -24,44 +24,55 @@ specific language governing permissions and limitations under the License. --> -## timestampdiff ## 描述 + +`timestampdiff` 函数用于计算两个时间戳或日期之间的差值,返回两个时间戳之间的时间间隔。可以计算两者之间的差异,以指定的时间单位(如秒、分钟、小时、天、月、年等)返回结果。 + ## 语法 -`INT TIMESTAMPDIFF(unit, DATETIME datetime_expr1, DATETIME datetime_expr2)` +`TIMESTAMPDIFF(unit, DATETIME datetime_expr1, DATETIME datetime_expr2)` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `unit` | 时间单位,指定要返回差异的单位,常见的值有 SECOND、MINUTE、HOUR、DAY、MONTH、YEAR 等 | +|`DATETIME datetime_expr1`| 第一个日期时间,合法的目标时间戳或日期 | +|`DATETIME datetime_expr2`| 第二个日期时间,合法的目标时间戳或日期 | -返回datetime_expr2−datetime_expr1,其中datetime_expr1和datetime_expr2是日期或日期时间表达式。 +## 返回值 -结果(整数)的单位由unit参数给出。interval的单位由unit参数给出,它应该是下列值之一: - -SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, or YEAR。 + 返回两个日期时间之间的差异,单位根据 unit 参数确定。 ## 举例 +```sql +SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'); ``` - -MySQL> SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'); +```text +--------------------------------------------------------------------+ | timestampdiff(MONTH, '2003-02-01 00:00:00', '2003-05-01 00:00:00') | +--------------------------------------------------------------------+ | 3 | +--------------------------------------------------------------------+ - -MySQL> SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01'); +``` +```sql +SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01'); +``` +```text +-------------------------------------------------------------------+ | timestampdiff(YEAR, '2002-05-01 00:00:00', '2001-01-01 00:00:00') | +-------------------------------------------------------------------+ | -1 | +-------------------------------------------------------------------+ - - -MySQL> SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55'); +``` +```sql +SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55'); +``` +```text +---------------------------------------------------------------------+ | timestampdiff(MINUTE, '2003-02-01 00:00:00', '2003-05-01 12:05:55') | +---------------------------------------------------------------------+ | 128885 | +---------------------------------------------------------------------+ - ``` -### keywords - TIMESTAMPDIFF diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md index 7dbc4146ad69d..df887d244b64c 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md @@ -1,6 +1,6 @@ --- { - "title": "date_ceil", + "title": "DATE_CEIL", "language": "zh-CN" } --- @@ -24,83 +24,83 @@ specific language governing permissions and limitations under the License. --> -## date_ceil ## 描述 -**Syntax** -`DATETIME DATE_CEIL(DATETIME datetime, INTERVAL period type)` +`date_ceil` 将日期转化为指定的时间间隔周期的最近上取整时刻。 +## 语法 -将日期转化为指定的时间间隔周期的最近上取整时刻。 +`DATE_CEIL(DATETIME datetime, INTERVAL period type)` -datetime 参数是合法的日期表达式。 +## 参数 -period 参数是指定每个周期有多少个单位组成,开始的时间起点为0001-01-01T00:00:00. +| 参数 | 说明 | +| -- | -- | +| `datetime` | 参数是合法的日期表达式 | +| `period` | 参数是指定每个周期有多少个单位组成,开始的时间起点为0001-01-01T00:00:00 | +| `type` | 参数可以是:YEAR, MONTH, DAY, HOUR, MINUTE, SECOND | -type 参数可以是下列值:YEAR, MONTH, DAY, HOUR, MINUTE, SECOND. +## 返回值 + +返回的是一个日期或时间值,表示将输入值向上舍入到指定单位的结果。 ## 举例 +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 second); ``` -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 second); +```text +--------------------------------------------------------------+ | second_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +--------------------------------------------------------------+ | 2023-07-13 22:28:20 | +--------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 minute); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 minute); +--------------------------------------------------------------+ | minute_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +--------------------------------------------------------------+ | 2023-07-13 22:30:00 | +--------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 hour); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 hour); +``` +```text +------------------------------------------------------------+ | hour_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +------------------------------------------------------------+ | 2023-07-13 23:00:00 | +------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 day); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 day); +``` +```text +-----------------------------------------------------------+ | day_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +-----------------------------------------------------------+ | 2023-07-15 00:00:00 | +-----------------------------------------------------------+ -1 row in set (0.00 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 month); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 month); +``` +```text +-------------------------------------------------------------+ | month_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +-------------------------------------------------------------+ | 2023-12-01 00:00:00 | +-------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 year); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 year); +``` +```text +------------------------------------------------------------+ | year_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +------------------------------------------------------------+ | 2026-01-01 00:00:00 | +------------------------------------------------------------+ -1 row in set (0.00 sec) ``` - -### Keywords - - DATE_CEIL,DATE,CEIL - -### Best Practices - -还可参阅: -- [second_ceil](./second_ceil) -- [minute_ceil](./minute_ceil) -- [hour_ceil](./hour_ceil) -- [day_ceil](./day_ceil) -- [month_ceil](./month_ceil) -- [year_ceil](./year_ceil) diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md index 0219a2406334c..291a32180abfa 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md @@ -1,6 +1,6 @@ --- { - "title": "date_floor", + "title": "DATE_FLOOR", "language": "zh-CN" } --- @@ -24,91 +24,95 @@ specific language governing permissions and limitations under the License. --> -## date_floor ## 描述 -## 语法 -`DATETIME DATE_FLOOR(DATETIME datetime, INTERVAL period type)` +`date_floor` 将日期转化为指定的时间间隔周期的最近下取整时刻。 + +## 语法 +`DATE_FLOOR(DATETIME datetime, INTERVAL period type)` -将日期转化为指定的时间间隔周期的最近下取整时刻。 +## 参数 -datetime 参数是合法的日期表达式。 +| 参数 | 说明 | +| -- | -- | +| `datetime` | 参数是合法的日期表达式 | +| `period` | 参数是指定每个周期有多少个单位组成,开始的时间起点为0001-01-01T00:00:00 | +| `type` | 参数可以是:YEAR, MONTH, DAY, HOUR, MINUTE, SECOND | -period 参数是指定每个周期有多少个单位组成,开始的时间起点为0001-01-01T00:00:00. +## 返回值 -type 参数可以是下列值:YEAR, MONTH, DAY, HOUR, MINUTE, SECOND. +返回的是一个日期或时间值,表示将输入值向下舍入到指定单位的结果。 ## 举例 +```sql +select date_floor("0001-01-01 00:00:16",interval 5 second); ``` -mysql>select date_floor("0001-01-01 00:00:16",interval 5 second); +```text +---------------------------------------------------------------+ | second_floor('0001-01-01 00:00:16', 5, '0001-01-01 00:00:00') | +---------------------------------------------------------------+ | 0001-01-01 00:00:15 | +---------------------------------------------------------------+ -1 row in set (0.00 sec) - -mysql>select date_floor("0001-01-01 00:00:18",interval 5 second); +``` +```sql +select date_floor("0001-01-01 00:00:18",interval 5 second); +``` +```text +---------------------------------------------------------------+ | second_floor('0001-01-01 00:00:18', 5, '0001-01-01 00:00:00') | +---------------------------------------------------------------+ | 0001-01-01 00:00:15 | +---------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 minute); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 minute); +``` +```text +---------------------------------------------------------------+ | minute_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +---------------------------------------------------------------+ | 2023-07-13 22:25:00 | +---------------------------------------------------------------+ -1 row in set (0.00 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 hour); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 hour); +``` +```text +-------------------------------------------------------------+ | hour_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +-------------------------------------------------------------+ | 2023-07-13 18:00:00 | +-------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 day); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 day); +``` +```text +------------------------------------------------------------+ | day_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +------------------------------------------------------------+ | 2023-07-10 00:00:00 | +------------------------------------------------------------+ -1 row in set (0.00 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 month); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 month); +``` +```text +--------------------------------------------------------------+ | month_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +--------------------------------------------------------------+ | 2023-07-01 00:00:00 | +--------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 year); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 year); +``` +```text +-------------------------------------------------------------+ | year_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +-------------------------------------------------------------+ | 2021-01-01 00:00:00 | +-------------------------------------------------------------+ - -``` - -### keywords - - DATE_FLOOR,DATE,FLOOR - -### Best Practice - -还可参阅: -- [second_ceil](./second_ceil) -- [minute_ceil](./minute_ceil) -- [hour_ceil](./hour_ceil) -- [day_ceil](./day_ceil) -- [month_ceil](./month_ceil) -- [year_ceil](./year_ceil) +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md index e2ee3efeb0990..5594fdcbf2ed9 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md @@ -24,31 +24,41 @@ specific language governing permissions and limitations under the License. --> -## extract ## 描述 + +`extract` 函数用于从日期或时间值中提取指定的部分,如年份、月份、日、小时、分钟、秒等。该函数常用于从日期时间字段中提取具体的时间组件进行计算、比较或展示。 + ## 语法 -`INT extract(unit FROM DATETIME)` +`EXTRACT(unit FROM DATETIME)` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `unit` | 提取DATETIME某个指定单位的值。单位可以为year, month, day, hour, minute, second 或者 microsecond | +|`from`| 固定语法 | +| `period` | 参数是合法的日期表达式 | -提取DATETIME某个指定单位的值。单位可以为year, month, day, hour, minute, second 或者 microsecond +## 返回值 + +返回的是提取出的日期或时间的某个部分(如整数),具体的部分取决于提取的单位。 ## 举例 +```sql +select extract(year from '2022-09-22 17:01:30') as year, +extract(month from '2022-09-22 17:01:30') as month, +extract(day from '2022-09-22 17:01:30') as day, +extract(hour from '2022-09-22 17:01:30') as hour, +extract(minute from '2022-09-22 17:01:30') as minute, +extract(second from '2022-09-22 17:01:30') as second, +extract(microsecond from cast('2022-09-22 17:01:30.000123' as datetimev2(6))) as microsecond; ``` -mysql> select extract(year from '2022-09-22 17:01:30') as year, - -> extract(month from '2022-09-22 17:01:30') as month, - -> extract(day from '2022-09-22 17:01:30') as day, - -> extract(hour from '2022-09-22 17:01:30') as hour, - -> extract(minute from '2022-09-22 17:01:30') as minute, - -> extract(second from '2022-09-22 17:01:30') as second, - -> extract(microsecond from cast('2022-09-22 17:01:30.000123' as datetimev2(6))) as microsecond; +```text +------+-------+------+------+--------+--------+-------------+ | year | month | day | hour | minute | second | microsecond | +------+-------+------+------+--------+--------+-------------+ | 2022 | 9 | 22 | 17 | 1 | 30 | 123 | +------+-------+------+------+--------+--------+-------------+ ``` - -### keywords - - extract diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md index e56f3dbdbe2be..8ebf0bc6440c8 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md @@ -24,36 +24,45 @@ specific language governing permissions and limitations under the License. --> -## timestampadd ## 描述 + +`timestampadd` 函数用于将指定的时间单位(如年、月、日、小时、分钟、秒等)添加到一个时间戳或日期上。这个函数通常用于日期和时间的计算。 + ## 语法 -`DATETIME TIMESTAMPADD(unit, interval, DATETIME datetime_expr)` +`TIMESTAMPADD(unit, interval, DATETIME datetime_expr)` +## 参数 -将整数表达式间隔添加到日期或日期时间表达式datetime_expr中。 +| 参数 | 说明 | +| -- | -- | +| `unit` | 时间单位,指定要添加的时间单位,常见的值有 SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR| +|`interval`| 要添加的时间间隔,通常是一个整数,可以是正数或负数,表示添加或减去的时间长度 | +| `DATETIME datetime_expr` | 合法的目标时间戳或日期 | -interval的单位由unit参数给出,它应该是下列值之一: +## 返回值 -SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, or YEAR。 +返回新的日期时间,表示在指定时间点上添加或减去指定时间间隔后的结果。 ## 举例 +```sql +SELECT TIMESTAMPADD(MINUTE,1,'2019-01-02'); ``` - -mysql> SELECT TIMESTAMPADD(MINUTE,1,'2019-01-02'); +```text +------------------------------------------------+ | timestampadd(MINUTE, 1, '2019-01-02 00:00:00') | +------------------------------------------------+ | 2019-01-02 00:01:00 | +------------------------------------------------+ - -mysql> SELECT TIMESTAMPADD(WEEK,1,'2019-01-02'); +``` +```sql +SELECT TIMESTAMPADD(WEEK,1,'2019-01-02'); +``` +```text +----------------------------------------------+ | timestampadd(WEEK, 1, '2019-01-02 00:00:00') | +----------------------------------------------+ | 2019-01-09 00:00:00 | +----------------------------------------------+ ``` -### keywords - TIMESTAMPADD diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md index 587c23a130ac3..5bab33559541d 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md @@ -24,44 +24,55 @@ specific language governing permissions and limitations under the License. --> -## timestampdiff ## 描述 + +`timestampdiff` 函数用于计算两个时间戳或日期之间的差值,返回两个时间戳之间的时间间隔。可以计算两者之间的差异,以指定的时间单位(如秒、分钟、小时、天、月、年等)返回结果。 + ## 语法 -`INT TIMESTAMPDIFF(unit, DATETIME datetime_expr1, DATETIME datetime_expr2)` +`TIMESTAMPDIFF(unit, DATETIME datetime_expr1, DATETIME datetime_expr2)` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `unit` | 时间单位,指定要返回差异的单位,常见的值有 SECOND、MINUTE、HOUR、DAY、MONTH、YEAR 等 | +|`DATETIME datetime_expr1`| 第一个日期时间,合法的目标时间戳或日期 | +|`DATETIME datetime_expr2`| 第二个日期时间,合法的目标时间戳或日期 | -返回datetime_expr2−datetime_expr1,其中datetime_expr1和datetime_expr2是日期或日期时间表达式。 +## 返回值 -结果(整数)的单位由unit参数给出。interval的单位由unit参数给出,它应该是下列值之一: - -SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, or YEAR。 + 返回两个日期时间之间的差异,单位根据 unit 参数确定。 ## 举例 +```sql +SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'); ``` - -MySQL> SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'); +```text +--------------------------------------------------------------------+ | timestampdiff(MONTH, '2003-02-01 00:00:00', '2003-05-01 00:00:00') | +--------------------------------------------------------------------+ | 3 | +--------------------------------------------------------------------+ - -MySQL> SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01'); +``` +```sql +SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01'); +``` +```text +-------------------------------------------------------------------+ | timestampdiff(YEAR, '2002-05-01 00:00:00', '2001-01-01 00:00:00') | +-------------------------------------------------------------------+ | -1 | +-------------------------------------------------------------------+ - - -MySQL> SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55'); +``` +```sql +SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55'); +``` +```text +---------------------------------------------------------------------+ | timestampdiff(MINUTE, '2003-02-01 00:00:00', '2003-05-01 12:05:55') | +---------------------------------------------------------------------+ | 128885 | +---------------------------------------------------------------------+ - ``` -### keywords - TIMESTAMPDIFF diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md index 7dbc4146ad69d..df887d244b64c 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md @@ -1,6 +1,6 @@ --- { - "title": "date_ceil", + "title": "DATE_CEIL", "language": "zh-CN" } --- @@ -24,83 +24,83 @@ specific language governing permissions and limitations under the License. --> -## date_ceil ## 描述 -**Syntax** -`DATETIME DATE_CEIL(DATETIME datetime, INTERVAL period type)` +`date_ceil` 将日期转化为指定的时间间隔周期的最近上取整时刻。 +## 语法 -将日期转化为指定的时间间隔周期的最近上取整时刻。 +`DATE_CEIL(DATETIME datetime, INTERVAL period type)` -datetime 参数是合法的日期表达式。 +## 参数 -period 参数是指定每个周期有多少个单位组成,开始的时间起点为0001-01-01T00:00:00. +| 参数 | 说明 | +| -- | -- | +| `datetime` | 参数是合法的日期表达式 | +| `period` | 参数是指定每个周期有多少个单位组成,开始的时间起点为0001-01-01T00:00:00 | +| `type` | 参数可以是:YEAR, MONTH, DAY, HOUR, MINUTE, SECOND | -type 参数可以是下列值:YEAR, MONTH, DAY, HOUR, MINUTE, SECOND. +## 返回值 + +返回的是一个日期或时间值,表示将输入值向上舍入到指定单位的结果。 ## 举例 +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 second); ``` -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 second); +```text +--------------------------------------------------------------+ | second_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +--------------------------------------------------------------+ | 2023-07-13 22:28:20 | +--------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 minute); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 minute); +--------------------------------------------------------------+ | minute_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +--------------------------------------------------------------+ | 2023-07-13 22:30:00 | +--------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 hour); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 hour); +``` +```text +------------------------------------------------------------+ | hour_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +------------------------------------------------------------+ | 2023-07-13 23:00:00 | +------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 day); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 day); +``` +```text +-----------------------------------------------------------+ | day_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +-----------------------------------------------------------+ | 2023-07-15 00:00:00 | +-----------------------------------------------------------+ -1 row in set (0.00 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 month); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 month); +``` +```text +-------------------------------------------------------------+ | month_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +-------------------------------------------------------------+ | 2023-12-01 00:00:00 | +-------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 year); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 year); +``` +```text +------------------------------------------------------------+ | year_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +------------------------------------------------------------+ | 2026-01-01 00:00:00 | +------------------------------------------------------------+ -1 row in set (0.00 sec) ``` - -### Keywords - - DATE_CEIL,DATE,CEIL - -### Best Practices - -还可参阅: -- [second_ceil](./second_ceil) -- [minute_ceil](./minute_ceil) -- [hour_ceil](./hour_ceil) -- [day_ceil](./day_ceil) -- [month_ceil](./month_ceil) -- [year_ceil](./year_ceil) diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md index 0219a2406334c..291a32180abfa 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md @@ -1,6 +1,6 @@ --- { - "title": "date_floor", + "title": "DATE_FLOOR", "language": "zh-CN" } --- @@ -24,91 +24,95 @@ specific language governing permissions and limitations under the License. --> -## date_floor ## 描述 -## 语法 -`DATETIME DATE_FLOOR(DATETIME datetime, INTERVAL period type)` +`date_floor` 将日期转化为指定的时间间隔周期的最近下取整时刻。 + +## 语法 +`DATE_FLOOR(DATETIME datetime, INTERVAL period type)` -将日期转化为指定的时间间隔周期的最近下取整时刻。 +## 参数 -datetime 参数是合法的日期表达式。 +| 参数 | 说明 | +| -- | -- | +| `datetime` | 参数是合法的日期表达式 | +| `period` | 参数是指定每个周期有多少个单位组成,开始的时间起点为0001-01-01T00:00:00 | +| `type` | 参数可以是:YEAR, MONTH, DAY, HOUR, MINUTE, SECOND | -period 参数是指定每个周期有多少个单位组成,开始的时间起点为0001-01-01T00:00:00. +## 返回值 -type 参数可以是下列值:YEAR, MONTH, DAY, HOUR, MINUTE, SECOND. +返回的是一个日期或时间值,表示将输入值向下舍入到指定单位的结果。 ## 举例 +```sql +select date_floor("0001-01-01 00:00:16",interval 5 second); ``` -mysql>select date_floor("0001-01-01 00:00:16",interval 5 second); +```text +---------------------------------------------------------------+ | second_floor('0001-01-01 00:00:16', 5, '0001-01-01 00:00:00') | +---------------------------------------------------------------+ | 0001-01-01 00:00:15 | +---------------------------------------------------------------+ -1 row in set (0.00 sec) - -mysql>select date_floor("0001-01-01 00:00:18",interval 5 second); +``` +```sql +select date_floor("0001-01-01 00:00:18",interval 5 second); +``` +```text +---------------------------------------------------------------+ | second_floor('0001-01-01 00:00:18', 5, '0001-01-01 00:00:00') | +---------------------------------------------------------------+ | 0001-01-01 00:00:15 | +---------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 minute); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 minute); +``` +```text +---------------------------------------------------------------+ | minute_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +---------------------------------------------------------------+ | 2023-07-13 22:25:00 | +---------------------------------------------------------------+ -1 row in set (0.00 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 hour); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 hour); +``` +```text +-------------------------------------------------------------+ | hour_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +-------------------------------------------------------------+ | 2023-07-13 18:00:00 | +-------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 day); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 day); +``` +```text +------------------------------------------------------------+ | day_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +------------------------------------------------------------+ | 2023-07-10 00:00:00 | +------------------------------------------------------------+ -1 row in set (0.00 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 month); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 month); +``` +```text +--------------------------------------------------------------+ | month_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +--------------------------------------------------------------+ | 2023-07-01 00:00:00 | +--------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 year); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 year); +``` +```text +-------------------------------------------------------------+ | year_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +-------------------------------------------------------------+ | 2021-01-01 00:00:00 | +-------------------------------------------------------------+ - -``` - -### keywords - - DATE_FLOOR,DATE,FLOOR - -### Best Practice - -还可参阅: -- [second_ceil](./second_ceil) -- [minute_ceil](./minute_ceil) -- [hour_ceil](./hour_ceil) -- [day_ceil](./day_ceil) -- [month_ceil](./month_ceil) -- [year_ceil](./year_ceil) +``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md index e2ee3efeb0990..5594fdcbf2ed9 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md @@ -24,31 +24,41 @@ specific language governing permissions and limitations under the License. --> -## extract ## 描述 + +`extract` 函数用于从日期或时间值中提取指定的部分,如年份、月份、日、小时、分钟、秒等。该函数常用于从日期时间字段中提取具体的时间组件进行计算、比较或展示。 + ## 语法 -`INT extract(unit FROM DATETIME)` +`EXTRACT(unit FROM DATETIME)` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `unit` | 提取DATETIME某个指定单位的值。单位可以为year, month, day, hour, minute, second 或者 microsecond | +|`from`| 固定语法 | +| `period` | 参数是合法的日期表达式 | -提取DATETIME某个指定单位的值。单位可以为year, month, day, hour, minute, second 或者 microsecond +## 返回值 + +返回的是提取出的日期或时间的某个部分(如整数),具体的部分取决于提取的单位。 ## 举例 +```sql +select extract(year from '2022-09-22 17:01:30') as year, +extract(month from '2022-09-22 17:01:30') as month, +extract(day from '2022-09-22 17:01:30') as day, +extract(hour from '2022-09-22 17:01:30') as hour, +extract(minute from '2022-09-22 17:01:30') as minute, +extract(second from '2022-09-22 17:01:30') as second, +extract(microsecond from cast('2022-09-22 17:01:30.000123' as datetimev2(6))) as microsecond; ``` -mysql> select extract(year from '2022-09-22 17:01:30') as year, - -> extract(month from '2022-09-22 17:01:30') as month, - -> extract(day from '2022-09-22 17:01:30') as day, - -> extract(hour from '2022-09-22 17:01:30') as hour, - -> extract(minute from '2022-09-22 17:01:30') as minute, - -> extract(second from '2022-09-22 17:01:30') as second, - -> extract(microsecond from cast('2022-09-22 17:01:30.000123' as datetimev2(6))) as microsecond; +```text +------+-------+------+------+--------+--------+-------------+ | year | month | day | hour | minute | second | microsecond | +------+-------+------+------+--------+--------+-------------+ | 2022 | 9 | 22 | 17 | 1 | 30 | 123 | +------+-------+------+------+--------+--------+-------------+ ``` - -### keywords - - extract diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md index e56f3dbdbe2be..8ebf0bc6440c8 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md @@ -24,36 +24,45 @@ specific language governing permissions and limitations under the License. --> -## timestampadd ## 描述 + +`timestampadd` 函数用于将指定的时间单位(如年、月、日、小时、分钟、秒等)添加到一个时间戳或日期上。这个函数通常用于日期和时间的计算。 + ## 语法 -`DATETIME TIMESTAMPADD(unit, interval, DATETIME datetime_expr)` +`TIMESTAMPADD(unit, interval, DATETIME datetime_expr)` +## 参数 -将整数表达式间隔添加到日期或日期时间表达式datetime_expr中。 +| 参数 | 说明 | +| -- | -- | +| `unit` | 时间单位,指定要添加的时间单位,常见的值有 SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR| +|`interval`| 要添加的时间间隔,通常是一个整数,可以是正数或负数,表示添加或减去的时间长度 | +| `DATETIME datetime_expr` | 合法的目标时间戳或日期 | -interval的单位由unit参数给出,它应该是下列值之一: +## 返回值 -SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, or YEAR。 +返回新的日期时间,表示在指定时间点上添加或减去指定时间间隔后的结果。 ## 举例 +```sql +SELECT TIMESTAMPADD(MINUTE,1,'2019-01-02'); ``` - -mysql> SELECT TIMESTAMPADD(MINUTE,1,'2019-01-02'); +```text +------------------------------------------------+ | timestampadd(MINUTE, 1, '2019-01-02 00:00:00') | +------------------------------------------------+ | 2019-01-02 00:01:00 | +------------------------------------------------+ - -mysql> SELECT TIMESTAMPADD(WEEK,1,'2019-01-02'); +``` +```sql +SELECT TIMESTAMPADD(WEEK,1,'2019-01-02'); +``` +```text +----------------------------------------------+ | timestampadd(WEEK, 1, '2019-01-02 00:00:00') | +----------------------------------------------+ | 2019-01-09 00:00:00 | +----------------------------------------------+ ``` -### keywords - TIMESTAMPADD diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md index 587c23a130ac3..5bab33559541d 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md @@ -24,44 +24,55 @@ specific language governing permissions and limitations under the License. --> -## timestampdiff ## 描述 + +`timestampdiff` 函数用于计算两个时间戳或日期之间的差值,返回两个时间戳之间的时间间隔。可以计算两者之间的差异,以指定的时间单位(如秒、分钟、小时、天、月、年等)返回结果。 + ## 语法 -`INT TIMESTAMPDIFF(unit, DATETIME datetime_expr1, DATETIME datetime_expr2)` +`TIMESTAMPDIFF(unit, DATETIME datetime_expr1, DATETIME datetime_expr2)` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `unit` | 时间单位,指定要返回差异的单位,常见的值有 SECOND、MINUTE、HOUR、DAY、MONTH、YEAR 等 | +|`DATETIME datetime_expr1`| 第一个日期时间,合法的目标时间戳或日期 | +|`DATETIME datetime_expr2`| 第二个日期时间,合法的目标时间戳或日期 | -返回datetime_expr2−datetime_expr1,其中datetime_expr1和datetime_expr2是日期或日期时间表达式。 +## 返回值 -结果(整数)的单位由unit参数给出。interval的单位由unit参数给出,它应该是下列值之一: - -SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, or YEAR。 + 返回两个日期时间之间的差异,单位根据 unit 参数确定。 ## 举例 +```sql +SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'); ``` - -MySQL> SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'); +```text +--------------------------------------------------------------------+ | timestampdiff(MONTH, '2003-02-01 00:00:00', '2003-05-01 00:00:00') | +--------------------------------------------------------------------+ | 3 | +--------------------------------------------------------------------+ - -MySQL> SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01'); +``` +```sql +SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01'); +``` +```text +-------------------------------------------------------------------+ | timestampdiff(YEAR, '2002-05-01 00:00:00', '2001-01-01 00:00:00') | +-------------------------------------------------------------------+ | -1 | +-------------------------------------------------------------------+ - - -MySQL> SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55'); +``` +```sql +SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55'); +``` +```text +---------------------------------------------------------------------+ | timestampdiff(MINUTE, '2003-02-01 00:00:00', '2003-05-01 12:05:55') | +---------------------------------------------------------------------+ | 128885 | +---------------------------------------------------------------------+ - ``` -### keywords - TIMESTAMPDIFF diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md index c5971bed2f15b..d59f6e7d6978b 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md @@ -1,6 +1,6 @@ --- { - "title": "date_ceil", + "title": "DATE_CEIL", "language": "en" } --- @@ -24,83 +24,83 @@ specific language governing permissions and limitations under the License. --> -## date_ceil -### Description -**Syntax** +## Description -`DATETIME DATE_CEIL(DATETIME datetime, INTERVAL period type)` +`date_ceil` rounds a given date to the next upper boundary of the specified time interval. +## Syntax -Convert the date to the nearest rounding up time of the specified time interval period. +`DATE_CEIL(DATETIME datetime, INTERVAL period type)` -The datetime parameter is a valid date expression. +## Parameters -The period parameter specifies how many units each cycle consists of, starting from 0001-01-01T00:00:00 +| Parameter | Description | +| -- | -- | +| `datetime` | The argument is a valid date expression | +| `period` | The argument specifies how many units make up each period, with the start time being 0001-01-01T00:00:00 | +| `type` | The argument can be: YEAR, MONTH, DAY, HOUR, MINUTE, SECOND| -Type: YEAR, MONTH, DAY, HOUR, MINUTE, SECOND. +## Return Value -### Example +The return value is a date or time, representing the result of rounding the input value up to the specified unit. +## Examples + +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 second); ``` -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 second); +```text +--------------------------------------------------------------+ | second_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +--------------------------------------------------------------+ | 2023-07-13 22:28:20 | +--------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 minute); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 minute); +--------------------------------------------------------------+ | minute_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +--------------------------------------------------------------+ | 2023-07-13 22:30:00 | +--------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 hour); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 hour); +``` +```text +------------------------------------------------------------+ | hour_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +------------------------------------------------------------+ | 2023-07-13 23:00:00 | +------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 day); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 day); +``` +```text +-----------------------------------------------------------+ | day_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +-----------------------------------------------------------+ | 2023-07-15 00:00:00 | +-----------------------------------------------------------+ -1 row in set (0.00 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 month); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 month); +``` +```text +-------------------------------------------------------------+ | month_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +-------------------------------------------------------------+ | 2023-12-01 00:00:00 | +-------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 year); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 year); +``` +```text +------------------------------------------------------------+ | year_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +------------------------------------------------------------+ | 2026-01-01 00:00:00 | +------------------------------------------------------------+ -1 row in set (0.00 sec) -``` - -### Keywords - - DATE_CEIL,DATE,CEIL - -### Best Practices - -See also -- [second_ceil](./second_ceil) -- [minute_ceil](./minute_ceil) -- [hour_ceil](./hour_ceil) -- [day_ceil](./day_ceil) -- [month_ceil](./month_ceil) -- [year_ceil](./year_ceil) +``` \ No newline at end of file diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md index 565c72439be4f..3841898e3d4d2 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md @@ -1,6 +1,6 @@ --- { - "title": "date_floor", + "title": "DATE_FLOOR", "language": "en" } --- @@ -24,91 +24,95 @@ specific language governing permissions and limitations under the License. --> -## date_floor -### Description -**Syntax** +## Description -`DATETIME DATE_FLOOR(DATETIME datetime, INTERVAL period type)` +`date_floor` rounds a given date to the closest lower boundary of the specified time interval. +## Syntax -Converts a date to the nearest rounding down time of a specified time interval period. +`DATE_FLOOR(DATETIME datetime, INTERVAL period type)` -The datetime parameter is a valid date expression. +## Parameters -The period parameter specifies how many units each cycle consists of, starting from 0001-01-01T00:00:00 +| Parameter | Description | +| -- | -- | +| `datetime` | The argument is a valid date expression | +| `period` | The argument specifies how many units make up each period, with the start time being 0001-01-01T00:00:00 | +| `type` | The argument can be: YEAR, MONTH, DAY, HOUR, MINUTE, SECOND| -Type: YEAR, MONTH, DAY, HOUR, MINUTE, SECOND. +## Return Value -### Example +The return value is a date or time, representing the result of rounding the input value down to the specified unit. +## Examples + +```sql +select date_floor("0001-01-01 00:00:16",interval 5 second); ``` -mysql>select date_floor("0001-01-01 00:00:16",interval 5 second); +```text +---------------------------------------------------------------+ | second_floor('0001-01-01 00:00:16', 5, '0001-01-01 00:00:00') | +---------------------------------------------------------------+ | 0001-01-01 00:00:15 | +---------------------------------------------------------------+ -1 row in set (0.00 sec) - -mysql>select date_floor("0001-01-01 00:00:18",interval 5 second); +``` +```sql +select date_floor("0001-01-01 00:00:18",interval 5 second); +``` +```text +---------------------------------------------------------------+ | second_floor('0001-01-01 00:00:18', 5, '0001-01-01 00:00:00') | +---------------------------------------------------------------+ | 0001-01-01 00:00:15 | +---------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 minute); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 minute); +``` +```text +---------------------------------------------------------------+ | minute_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +---------------------------------------------------------------+ | 2023-07-13 22:25:00 | +---------------------------------------------------------------+ -1 row in set (0.00 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 hour); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 hour); +``` +```text +-------------------------------------------------------------+ | hour_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +-------------------------------------------------------------+ | 2023-07-13 18:00:00 | +-------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 day); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 day); +``` +```text +------------------------------------------------------------+ | day_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +------------------------------------------------------------+ | 2023-07-10 00:00:00 | +------------------------------------------------------------+ -1 row in set (0.00 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 month); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 month); +``` +```text +--------------------------------------------------------------+ | month_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +--------------------------------------------------------------+ | 2023-07-01 00:00:00 | +--------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 year); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 year); +``` +```text +-------------------------------------------------------------+ | year_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +-------------------------------------------------------------+ | 2021-01-01 00:00:00 | +-------------------------------------------------------------+ - -``` - -### Keywords - - DATE_FLOOR,DATE,FLOOR - -### Best Practices - -See also -- [second_floor](./second_floor) -- [minute_floor](./minute_floor) -- [hour_floor](./hour_floor) -- [day_floor](./day_floor) -- [month_floor](./month_floor) -- [year_floor](./year_floor) +``` \ No newline at end of file diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md index 19e2f9a271fe9..8c17aca87b305 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md @@ -24,31 +24,41 @@ specific language governing permissions and limitations under the License. --> -## extract -### description -#### Syntax +## Description -`INT extract(unit FROM DATETIME)` +The `extract` function is used to extract a specified part of a date or time value, such as the year, month, day, hour, minute, second, etc. This function is commonly used to extract specific time components from a datetime field for calculation, comparison, or display. -Extract DATETIME The value of a specified unit. The unit can be year, day, hour, minute, second or microsecond +## Syntax -### Example +`EXTRACT(unit FROM DATETIME)` +## Parameters + +| Parameter | Description | +| -- | -- | +| `unit` | The unit to extract from the DATETIME. Possible values are year, month, day, hour, minute, second, or microsecond | +| `from` | Fixed syntax | +| `period` | The argument is a valid date expression | + +## Return Value + +The return value is the extracted part of the date or time (such as an integer), depending on the unit being extracted. + +## Examples + +```sql +select extract(year from '2022-09-22 17:01:30') as year, +extract(month from '2022-09-22 17:01:30') as month, +extract(day from '2022-09-22 17:01:30') as day, +extract(hour from '2022-09-22 17:01:30') as hour, +extract(minute from '2022-09-22 17:01:30') as minute, +extract(second from '2022-09-22 17:01:30') as second, +extract(microsecond from cast('2022-09-22 17:01:30.000123' as datetimev2(6))) as microsecond; ``` -mysql> select extract(year from '2022-09-22 17:01:30') as year, - -> extract(month from '2022-09-22 17:01:30') as month, - -> extract(day from '2022-09-22 17:01:30') as day, - -> extract(hour from '2022-09-22 17:01:30') as hour, - -> extract(minute from '2022-09-22 17:01:30') as minute, - -> extract(second from '2022-09-22 17:01:30') as second, - -> extract(microsecond from cast('2022-09-22 17:01:30.000123' as datetimev2(6))) as microsecond; +```text +------+-------+------+------+--------+--------+-------------+ | year | month | day | hour | minute | second | microsecond | +------+-------+------+------+--------+--------+-------------+ | 2022 | 9 | 22 | 17 | 1 | 30 | 123 | +------+-------+------+------+--------+--------+-------------+ ``` - -### keywords - - extract diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md index 2d97cb0824776..3b9f5f09b2ac5 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md @@ -24,35 +24,45 @@ specific language governing permissions and limitations under the License. --> -## timestampadd -### description -#### Syntax +## Description -`DATETIME TIMESTAMPADD(unit, interval, DATETIME datetime_expr)` +The `timestampadd` function is used to add a specified time unit (such as year, month, day, hour, minute, second, etc.) to a timestamp or date. This function is commonly used for date and time calculations. -Adds the integer expression interval to the date or datetime expression datetime_expr. +## Syntax -The unit for interval is given by the unit argument, which should be one of the following values: +`TIMESTAMPADD(unit, interval, DATETIME datetime_expr)` -SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, or YEAR. +## Parameters -### example +| Parameter | Description | +| -- | -- | +| `unit` | Time unit, specifies the time unit to add, common values include SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR | +| `interval` | The time interval to add, typically an integer, which can be positive or negative to add or subtract the time length | +| `DATETIME datetime_expr` | A valid target timestamp or date | -``` +## Return Value + +The return value is the new date and time, representing the result of adding or subtracting the specified time interval to the given timestamp. -mysql> SELECT TIMESTAMPADD(MINUTE,1,'2019-01-02'); +## Examples + +```sql +SELECT TIMESTAMPADD(MINUTE,1,'2019-01-02'); +``` +```text +------------------------------------------------+ | timestampadd(MINUTE, 1, '2019-01-02 00:00:00') | +------------------------------------------------+ | 2019-01-02 00:01:00 | +------------------------------------------------+ - -mysql> SELECT TIMESTAMPADD(WEEK,1,'2019-01-02'); +``` +```sql +SELECT TIMESTAMPADD(WEEK,1,'2019-01-02'); +``` +```text +----------------------------------------------+ | timestampadd(WEEK, 1, '2019-01-02 00:00:00') | +----------------------------------------------+ | 2019-01-09 00:00:00 | +----------------------------------------------+ ``` -### keywords - TIMESTAMPADD diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md index dd5769852d555..07aa4f6d8d172 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md @@ -24,44 +24,55 @@ specific language governing permissions and limitations under the License. --> -## timestampdiff -### description -#### Syntax +## Description -`INT TIMESTAMPDIFF(unit, DATETIME datetime_expr1, DATETIME datetime_expr2)` +The `timestampdiff` function is used to calculate the difference between two timestamps or dates and returns the time interval between them. The difference can be returned in the specified time unit (such as seconds, minutes, hours, days, months, years, etc.). -Returns datetime_expr2 − datetime_expr1, where datetime_expr1 and datetime_expr2 are date or datetime expressions. +## Syntax -The unit for the result (an integer) is given by the unit argument. - -The legal values for unit are the same as those listed in the description of the TIMESTAMPADD() function. +`TIMESTAMPDIFF(unit, DATETIME datetime_expr1, DATETIME datetime_expr2)` -### example +## Parameters -``` +| Parameter | Description | +| -- | -- | +| `unit` | Time unit, specifies the unit in which to return the difference, common values include SECOND, MINUTE, HOUR, DAY, MONTH, YEAR | +| `DATETIME datetime_expr1` | The first datetime, a valid target timestamp or date | +| `DATETIME datetime_expr2` | The second datetime, a valid target timestamp or date | + +## Return Value + +The return value is the difference between the two date-times, with the unit determined by the unit parameter. + +## Examples -MySQL> SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'); +```sql +SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'); +``` +```text +--------------------------------------------------------------------+ | timestampdiff(MONTH, '2003-02-01 00:00:00', '2003-05-01 00:00:00') | +--------------------------------------------------------------------+ | 3 | +--------------------------------------------------------------------+ - -MySQL> SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01'); +``` +```sql +SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01'); +``` +```text +-------------------------------------------------------------------+ | timestampdiff(YEAR, '2002-05-01 00:00:00', '2001-01-01 00:00:00') | +-------------------------------------------------------------------+ | -1 | +-------------------------------------------------------------------+ - - -MySQL> SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55'); +``` +```sql +SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55'); +``` +```text +---------------------------------------------------------------------+ | timestampdiff(MINUTE, '2003-02-01 00:00:00', '2003-05-01 12:05:55') | +---------------------------------------------------------------------+ | 128885 | +---------------------------------------------------------------------+ - -``` -### keywords - TIMESTAMPDIFF +``` \ No newline at end of file diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md index c5971bed2f15b..d59f6e7d6978b 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md @@ -1,6 +1,6 @@ --- { - "title": "date_ceil", + "title": "DATE_CEIL", "language": "en" } --- @@ -24,83 +24,83 @@ specific language governing permissions and limitations under the License. --> -## date_ceil -### Description -**Syntax** +## Description -`DATETIME DATE_CEIL(DATETIME datetime, INTERVAL period type)` +`date_ceil` rounds a given date to the next upper boundary of the specified time interval. +## Syntax -Convert the date to the nearest rounding up time of the specified time interval period. +`DATE_CEIL(DATETIME datetime, INTERVAL period type)` -The datetime parameter is a valid date expression. +## Parameters -The period parameter specifies how many units each cycle consists of, starting from 0001-01-01T00:00:00 +| Parameter | Description | +| -- | -- | +| `datetime` | The argument is a valid date expression | +| `period` | The argument specifies how many units make up each period, with the start time being 0001-01-01T00:00:00 | +| `type` | The argument can be: YEAR, MONTH, DAY, HOUR, MINUTE, SECOND| -Type: YEAR, MONTH, DAY, HOUR, MINUTE, SECOND. +## Return Value -### Example +The return value is a date or time, representing the result of rounding the input value up to the specified unit. +## Examples + +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 second); ``` -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 second); +```text +--------------------------------------------------------------+ | second_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +--------------------------------------------------------------+ | 2023-07-13 22:28:20 | +--------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 minute); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 minute); +--------------------------------------------------------------+ | minute_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +--------------------------------------------------------------+ | 2023-07-13 22:30:00 | +--------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 hour); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 hour); +``` +```text +------------------------------------------------------------+ | hour_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +------------------------------------------------------------+ | 2023-07-13 23:00:00 | +------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 day); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 day); +``` +```text +-----------------------------------------------------------+ | day_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +-----------------------------------------------------------+ | 2023-07-15 00:00:00 | +-----------------------------------------------------------+ -1 row in set (0.00 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 month); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 month); +``` +```text +-------------------------------------------------------------+ | month_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +-------------------------------------------------------------+ | 2023-12-01 00:00:00 | +-------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql [(none)]>select date_ceil("2023-07-13 22:28:18",interval 5 year); +``` +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 year); +``` +```text +------------------------------------------------------------+ | year_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +------------------------------------------------------------+ | 2026-01-01 00:00:00 | +------------------------------------------------------------+ -1 row in set (0.00 sec) -``` - -### Keywords - - DATE_CEIL,DATE,CEIL - -### Best Practices - -See also -- [second_ceil](./second_ceil) -- [minute_ceil](./minute_ceil) -- [hour_ceil](./hour_ceil) -- [day_ceil](./day_ceil) -- [month_ceil](./month_ceil) -- [year_ceil](./year_ceil) +``` \ No newline at end of file diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md index 565c72439be4f..3841898e3d4d2 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md @@ -1,6 +1,6 @@ --- { - "title": "date_floor", + "title": "DATE_FLOOR", "language": "en" } --- @@ -24,91 +24,95 @@ specific language governing permissions and limitations under the License. --> -## date_floor -### Description -**Syntax** +## Description -`DATETIME DATE_FLOOR(DATETIME datetime, INTERVAL period type)` +`date_floor` rounds a given date to the closest lower boundary of the specified time interval. +## Syntax -Converts a date to the nearest rounding down time of a specified time interval period. +`DATE_FLOOR(DATETIME datetime, INTERVAL period type)` -The datetime parameter is a valid date expression. +## Parameters -The period parameter specifies how many units each cycle consists of, starting from 0001-01-01T00:00:00 +| Parameter | Description | +| -- | -- | +| `datetime` | The argument is a valid date expression | +| `period` | The argument specifies how many units make up each period, with the start time being 0001-01-01T00:00:00 | +| `type` | The argument can be: YEAR, MONTH, DAY, HOUR, MINUTE, SECOND| -Type: YEAR, MONTH, DAY, HOUR, MINUTE, SECOND. +## Return Value -### Example +The return value is a date or time, representing the result of rounding the input value down to the specified unit. +## Examples + +```sql +select date_floor("0001-01-01 00:00:16",interval 5 second); ``` -mysql>select date_floor("0001-01-01 00:00:16",interval 5 second); +```text +---------------------------------------------------------------+ | second_floor('0001-01-01 00:00:16', 5, '0001-01-01 00:00:00') | +---------------------------------------------------------------+ | 0001-01-01 00:00:15 | +---------------------------------------------------------------+ -1 row in set (0.00 sec) - -mysql>select date_floor("0001-01-01 00:00:18",interval 5 second); +``` +```sql +select date_floor("0001-01-01 00:00:18",interval 5 second); +``` +```text +---------------------------------------------------------------+ | second_floor('0001-01-01 00:00:18', 5, '0001-01-01 00:00:00') | +---------------------------------------------------------------+ | 0001-01-01 00:00:15 | +---------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 minute); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 minute); +``` +```text +---------------------------------------------------------------+ | minute_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +---------------------------------------------------------------+ | 2023-07-13 22:25:00 | +---------------------------------------------------------------+ -1 row in set (0.00 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 hour); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 hour); +``` +```text +-------------------------------------------------------------+ | hour_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +-------------------------------------------------------------+ | 2023-07-13 18:00:00 | +-------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 day); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 day); +``` +```text +------------------------------------------------------------+ | day_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +------------------------------------------------------------+ | 2023-07-10 00:00:00 | +------------------------------------------------------------+ -1 row in set (0.00 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 month); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 month); +``` +```text +--------------------------------------------------------------+ | month_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +--------------------------------------------------------------+ | 2023-07-01 00:00:00 | +--------------------------------------------------------------+ -1 row in set (0.01 sec) - -mysql>select date_floor("2023-07-13 22:28:18",interval 5 year); +``` +```sql +select date_floor("2023-07-13 22:28:18",interval 5 year); +``` +```text +-------------------------------------------------------------+ | year_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | +-------------------------------------------------------------+ | 2021-01-01 00:00:00 | +-------------------------------------------------------------+ - -``` - -### Keywords - - DATE_FLOOR,DATE,FLOOR - -### Best Practices - -See also -- [second_floor](./second_floor) -- [minute_floor](./minute_floor) -- [hour_floor](./hour_floor) -- [day_floor](./day_floor) -- [month_floor](./month_floor) -- [year_floor](./year_floor) +``` \ No newline at end of file diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md index 19e2f9a271fe9..8c17aca87b305 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md @@ -24,31 +24,41 @@ specific language governing permissions and limitations under the License. --> -## extract -### description -#### Syntax +## Description -`INT extract(unit FROM DATETIME)` +The `extract` function is used to extract a specified part of a date or time value, such as the year, month, day, hour, minute, second, etc. This function is commonly used to extract specific time components from a datetime field for calculation, comparison, or display. -Extract DATETIME The value of a specified unit. The unit can be year, day, hour, minute, second or microsecond +## Syntax -### Example +`EXTRACT(unit FROM DATETIME)` +## Parameters + +| Parameter | Description | +| -- | -- | +| `unit` | The unit to extract from the DATETIME. Possible values are year, month, day, hour, minute, second, or microsecond | +| `from` | Fixed syntax | +| `period` | The argument is a valid date expression | + +## Return Value + +The return value is the extracted part of the date or time (such as an integer), depending on the unit being extracted. + +## Examples + +```sql +select extract(year from '2022-09-22 17:01:30') as year, +extract(month from '2022-09-22 17:01:30') as month, +extract(day from '2022-09-22 17:01:30') as day, +extract(hour from '2022-09-22 17:01:30') as hour, +extract(minute from '2022-09-22 17:01:30') as minute, +extract(second from '2022-09-22 17:01:30') as second, +extract(microsecond from cast('2022-09-22 17:01:30.000123' as datetimev2(6))) as microsecond; ``` -mysql> select extract(year from '2022-09-22 17:01:30') as year, - -> extract(month from '2022-09-22 17:01:30') as month, - -> extract(day from '2022-09-22 17:01:30') as day, - -> extract(hour from '2022-09-22 17:01:30') as hour, - -> extract(minute from '2022-09-22 17:01:30') as minute, - -> extract(second from '2022-09-22 17:01:30') as second, - -> extract(microsecond from cast('2022-09-22 17:01:30.000123' as datetimev2(6))) as microsecond; +```text +------+-------+------+------+--------+--------+-------------+ | year | month | day | hour | minute | second | microsecond | +------+-------+------+------+--------+--------+-------------+ | 2022 | 9 | 22 | 17 | 1 | 30 | 123 | +------+-------+------+------+--------+--------+-------------+ ``` - -### keywords - - extract diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md index 2d97cb0824776..3b9f5f09b2ac5 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md @@ -24,35 +24,45 @@ specific language governing permissions and limitations under the License. --> -## timestampadd -### description -#### Syntax +## Description -`DATETIME TIMESTAMPADD(unit, interval, DATETIME datetime_expr)` +The `timestampadd` function is used to add a specified time unit (such as year, month, day, hour, minute, second, etc.) to a timestamp or date. This function is commonly used for date and time calculations. -Adds the integer expression interval to the date or datetime expression datetime_expr. +## Syntax -The unit for interval is given by the unit argument, which should be one of the following values: +`TIMESTAMPADD(unit, interval, DATETIME datetime_expr)` -SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, or YEAR. +## Parameters -### example +| Parameter | Description | +| -- | -- | +| `unit` | Time unit, specifies the time unit to add, common values include SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR | +| `interval` | The time interval to add, typically an integer, which can be positive or negative to add or subtract the time length | +| `DATETIME datetime_expr` | A valid target timestamp or date | -``` +## Return Value + +The return value is the new date and time, representing the result of adding or subtracting the specified time interval to the given timestamp. -mysql> SELECT TIMESTAMPADD(MINUTE,1,'2019-01-02'); +## Examples + +```sql +SELECT TIMESTAMPADD(MINUTE,1,'2019-01-02'); +``` +```text +------------------------------------------------+ | timestampadd(MINUTE, 1, '2019-01-02 00:00:00') | +------------------------------------------------+ | 2019-01-02 00:01:00 | +------------------------------------------------+ - -mysql> SELECT TIMESTAMPADD(WEEK,1,'2019-01-02'); +``` +```sql +SELECT TIMESTAMPADD(WEEK,1,'2019-01-02'); +``` +```text +----------------------------------------------+ | timestampadd(WEEK, 1, '2019-01-02 00:00:00') | +----------------------------------------------+ | 2019-01-09 00:00:00 | +----------------------------------------------+ ``` -### keywords - TIMESTAMPADD diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md index dd5769852d555..07aa4f6d8d172 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md @@ -24,44 +24,55 @@ specific language governing permissions and limitations under the License. --> -## timestampdiff -### description -#### Syntax +## Description -`INT TIMESTAMPDIFF(unit, DATETIME datetime_expr1, DATETIME datetime_expr2)` +The `timestampdiff` function is used to calculate the difference between two timestamps or dates and returns the time interval between them. The difference can be returned in the specified time unit (such as seconds, minutes, hours, days, months, years, etc.). -Returns datetime_expr2 − datetime_expr1, where datetime_expr1 and datetime_expr2 are date or datetime expressions. +## Syntax -The unit for the result (an integer) is given by the unit argument. - -The legal values for unit are the same as those listed in the description of the TIMESTAMPADD() function. +`TIMESTAMPDIFF(unit, DATETIME datetime_expr1, DATETIME datetime_expr2)` -### example +## Parameters -``` +| Parameter | Description | +| -- | -- | +| `unit` | Time unit, specifies the unit in which to return the difference, common values include SECOND, MINUTE, HOUR, DAY, MONTH, YEAR | +| `DATETIME datetime_expr1` | The first datetime, a valid target timestamp or date | +| `DATETIME datetime_expr2` | The second datetime, a valid target timestamp or date | + +## Return Value + +The return value is the difference between the two date-times, with the unit determined by the unit parameter. + +## Examples -MySQL> SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'); +```sql +SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'); +``` +```text +--------------------------------------------------------------------+ | timestampdiff(MONTH, '2003-02-01 00:00:00', '2003-05-01 00:00:00') | +--------------------------------------------------------------------+ | 3 | +--------------------------------------------------------------------+ - -MySQL> SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01'); +``` +```sql +SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01'); +``` +```text +-------------------------------------------------------------------+ | timestampdiff(YEAR, '2002-05-01 00:00:00', '2001-01-01 00:00:00') | +-------------------------------------------------------------------+ | -1 | +-------------------------------------------------------------------+ - - -MySQL> SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55'); +``` +```sql +SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55'); +``` +```text +---------------------------------------------------------------------+ | timestampdiff(MINUTE, '2003-02-01 00:00:00', '2003-05-01 12:05:55') | +---------------------------------------------------------------------+ | 128885 | +---------------------------------------------------------------------+ - -``` -### keywords - TIMESTAMPDIFF +``` \ No newline at end of file From b5fd00164ae642f614a1a7208e758309fb7e8e28 Mon Sep 17 00:00:00 2001 From: yuanyuan Date: Fri, 17 Jan 2025 21:15:47 +0800 Subject: [PATCH 2/2] Modify as required --- .../date-time-functions/date-ceil.md | 12 +++++++++++- .../date-time-functions/date-floor.md | 15 ++++++++++++++- .../date-time-functions/extract.md | 6 +++--- .../date-time-functions/timestampadd.md | 7 +++++-- .../date-time-functions/timestampdiff.md | 11 ++++++++--- .../date-time-functions/date-ceil.md | 12 +++++++++++- .../date-time-functions/date-floor.md | 15 ++++++++++++++- .../date-time-functions/extract.md | 6 +++--- .../date-time-functions/timestampadd.md | 7 +++++-- .../date-time-functions/timestampdiff.md | 11 ++++++++--- .../date-time-functions/date-ceil.md | 12 +++++++++++- .../date-time-functions/date-floor.md | 15 ++++++++++++++- .../date-time-functions/extract.md | 6 +++--- .../date-time-functions/timestampadd.md | 7 +++++-- .../date-time-functions/timestampdiff.md | 11 ++++++++--- .../date-time-functions/date-ceil.md | 12 +++++++++++- .../date-time-functions/date-floor.md | 15 ++++++++++++++- .../date-time-functions/extract.md | 6 +++--- .../date-time-functions/timestampadd.md | 7 +++++-- .../date-time-functions/timestampdiff.md | 11 ++++++++--- .../date-time-functions/date-ceil.md | 12 +++++++++++- .../date-time-functions/date-floor.md | 15 ++++++++++++++- .../date-time-functions/extract.md | 6 +++--- .../date-time-functions/timestampadd.md | 7 +++++-- .../date-time-functions/timestampdiff.md | 11 ++++++++--- .../date-time-functions/date-ceil.md | 12 +++++++++++- .../date-time-functions/date-floor.md | 15 ++++++++++++++- .../date-time-functions/extract.md | 6 +++--- .../date-time-functions/timestampadd.md | 7 +++++-- .../date-time-functions/timestampdiff.md | 11 ++++++++--- 30 files changed, 246 insertions(+), 60 deletions(-) diff --git a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md index d59f6e7d6978b..6cc46d65b69b5 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md +++ b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md @@ -30,7 +30,7 @@ under the License. ## Syntax -`DATE_CEIL(DATETIME datetime, INTERVAL period type)` +`DATE_CEIL(, INTERVAL )` ## Parameters @@ -49,6 +49,7 @@ The return value is a date or time, representing the result of rounding the inpu ```sql select date_ceil("2023-07-13 22:28:18",interval 5 second); ``` + ```text +--------------------------------------------------------------+ | second_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -56,6 +57,7 @@ select date_ceil("2023-07-13 22:28:18",interval 5 second); | 2023-07-13 22:28:20 | +--------------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 minute); +--------------------------------------------------------------+ @@ -64,9 +66,11 @@ select date_ceil("2023-07-13 22:28:18",interval 5 minute); | 2023-07-13 22:30:00 | +--------------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 hour); ``` + ```text +------------------------------------------------------------+ | hour_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -74,9 +78,11 @@ select date_ceil("2023-07-13 22:28:18",interval 5 hour); | 2023-07-13 23:00:00 | +------------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 day); ``` + ```text +-----------------------------------------------------------+ | day_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -84,9 +90,11 @@ select date_ceil("2023-07-13 22:28:18",interval 5 day); | 2023-07-15 00:00:00 | +-----------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 month); ``` + ```text +-------------------------------------------------------------+ | month_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -94,9 +102,11 @@ select date_ceil("2023-07-13 22:28:18",interval 5 month); | 2023-12-01 00:00:00 | +-------------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 year); ``` + ```text +------------------------------------------------------------+ | year_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | diff --git a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md index 3841898e3d4d2..98b153bf5dc6c 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md +++ b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md @@ -30,7 +30,7 @@ under the License. ## Syntax -`DATE_FLOOR(DATETIME datetime, INTERVAL period type)` +`DATE_FLOOR(, INTERVAL )` ## Parameters @@ -49,6 +49,7 @@ The return value is a date or time, representing the result of rounding the inpu ```sql select date_floor("0001-01-01 00:00:16",interval 5 second); ``` + ```text +---------------------------------------------------------------+ | second_floor('0001-01-01 00:00:16', 5, '0001-01-01 00:00:00') | @@ -56,9 +57,11 @@ select date_floor("0001-01-01 00:00:16",interval 5 second); | 0001-01-01 00:00:15 | +---------------------------------------------------------------+ ``` + ```sql select date_floor("0001-01-01 00:00:18",interval 5 second); ``` + ```text +---------------------------------------------------------------+ | second_floor('0001-01-01 00:00:18', 5, '0001-01-01 00:00:00') | @@ -66,9 +69,11 @@ select date_floor("0001-01-01 00:00:18",interval 5 second); | 0001-01-01 00:00:15 | +---------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 minute); ``` + ```text +---------------------------------------------------------------+ | minute_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -76,9 +81,11 @@ select date_floor("2023-07-13 22:28:18",interval 5 minute); | 2023-07-13 22:25:00 | +---------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 hour); ``` + ```text +-------------------------------------------------------------+ | hour_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -86,9 +93,11 @@ select date_floor("2023-07-13 22:28:18",interval 5 hour); | 2023-07-13 18:00:00 | +-------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 day); ``` + ```text +------------------------------------------------------------+ | day_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -96,9 +105,11 @@ select date_floor("2023-07-13 22:28:18",interval 5 day); | 2023-07-10 00:00:00 | +------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 month); ``` + ```text +--------------------------------------------------------------+ | month_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -106,9 +117,11 @@ select date_floor("2023-07-13 22:28:18",interval 5 month); | 2023-07-01 00:00:00 | +--------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 year); ``` + ```text +-------------------------------------------------------------+ | year_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | diff --git a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md index 8c17aca87b305..8de48ce9cdcba 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md +++ b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md @@ -30,15 +30,14 @@ The `extract` function is used to extract a specified part of a date or time val ## Syntax -`EXTRACT(unit FROM DATETIME)` +`EXTRACT( FROM )` ## Parameters | Parameter | Description | | -- | -- | | `unit` | The unit to extract from the DATETIME. Possible values are year, month, day, hour, minute, second, or microsecond | -| `from` | Fixed syntax | -| `period` | The argument is a valid date expression | +| `datetime` | The argument is a valid date expression | ## Return Value @@ -55,6 +54,7 @@ extract(minute from '2022-09-22 17:01:30') as minute, extract(second from '2022-09-22 17:01:30') as second, extract(microsecond from cast('2022-09-22 17:01:30.000123' as datetimev2(6))) as microsecond; ``` + ```text +------+-------+------+------+--------+--------+-------------+ | year | month | day | hour | minute | second | microsecond | diff --git a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md index 3b9f5f09b2ac5..2c0c358c4f6d0 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md +++ b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md @@ -30,7 +30,7 @@ The `timestampadd` function is used to add a specified time unit (such as year, ## Syntax -`TIMESTAMPADD(unit, interval, DATETIME datetime_expr)` +`TIMESTAMPADD(, , )` ## Parameters @@ -38,7 +38,7 @@ The `timestampadd` function is used to add a specified time unit (such as year, | -- | -- | | `unit` | Time unit, specifies the time unit to add, common values include SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR | | `interval` | The time interval to add, typically an integer, which can be positive or negative to add or subtract the time length | -| `DATETIME datetime_expr` | A valid target timestamp or date | +| `datetime_expr` | A valid target timestamp or date | ## Return Value @@ -49,6 +49,7 @@ The return value is the new date and time, representing the result of adding or ```sql SELECT TIMESTAMPADD(MINUTE,1,'2019-01-02'); ``` + ```text +------------------------------------------------+ | timestampadd(MINUTE, 1, '2019-01-02 00:00:00') | @@ -56,9 +57,11 @@ SELECT TIMESTAMPADD(MINUTE,1,'2019-01-02'); | 2019-01-02 00:01:00 | +------------------------------------------------+ ``` + ```sql SELECT TIMESTAMPADD(WEEK,1,'2019-01-02'); ``` + ```text +----------------------------------------------+ | timestampadd(WEEK, 1, '2019-01-02 00:00:00') | diff --git a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md index 07aa4f6d8d172..bbabb256ae6e5 100644 --- a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md +++ b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md @@ -30,15 +30,15 @@ The `timestampdiff` function is used to calculate the difference between two tim ## Syntax -`TIMESTAMPDIFF(unit, DATETIME datetime_expr1, DATETIME datetime_expr2)` +`TIMESTAMPDIFF(, , )` ## Parameters | Parameter | Description | | -- | -- | | `unit` | Time unit, specifies the unit in which to return the difference, common values include SECOND, MINUTE, HOUR, DAY, MONTH, YEAR | -| `DATETIME datetime_expr1` | The first datetime, a valid target timestamp or date | -| `DATETIME datetime_expr2` | The second datetime, a valid target timestamp or date | +| `datetime_expr1` | The first datetime, a valid target timestamp or date | +| `datetime_expr2` | The second datetime, a valid target timestamp or date | ## Return Value @@ -49,6 +49,7 @@ The return value is the difference between the two date-times, with the unit det ```sql SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'); ``` + ```text +--------------------------------------------------------------------+ | timestampdiff(MONTH, '2003-02-01 00:00:00', '2003-05-01 00:00:00') | @@ -56,9 +57,11 @@ SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'); | 3 | +--------------------------------------------------------------------+ ``` + ```sql SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01'); ``` + ```text +-------------------------------------------------------------------+ | timestampdiff(YEAR, '2002-05-01 00:00:00', '2001-01-01 00:00:00') | @@ -66,9 +69,11 @@ SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01'); | -1 | +-------------------------------------------------------------------+ ``` + ```sql SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55'); ``` + ```text +---------------------------------------------------------------------+ | timestampdiff(MINUTE, '2003-02-01 00:00:00', '2003-05-01 12:05:55') | diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md index df887d244b64c..b4e040bd2591a 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md @@ -30,7 +30,7 @@ under the License. ## 语法 -`DATE_CEIL(DATETIME datetime, INTERVAL period type)` +`DATE_CEIL(, INTERVAL )` ## 参数 @@ -49,6 +49,7 @@ under the License. ```sql select date_ceil("2023-07-13 22:28:18",interval 5 second); ``` + ```text +--------------------------------------------------------------+ | second_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -56,6 +57,7 @@ select date_ceil("2023-07-13 22:28:18",interval 5 second); | 2023-07-13 22:28:20 | +--------------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 minute); +--------------------------------------------------------------+ @@ -64,9 +66,11 @@ select date_ceil("2023-07-13 22:28:18",interval 5 minute); | 2023-07-13 22:30:00 | +--------------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 hour); ``` + ```text +------------------------------------------------------------+ | hour_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -74,9 +78,11 @@ select date_ceil("2023-07-13 22:28:18",interval 5 hour); | 2023-07-13 23:00:00 | +------------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 day); ``` + ```text +-----------------------------------------------------------+ | day_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -84,9 +90,11 @@ select date_ceil("2023-07-13 22:28:18",interval 5 day); | 2023-07-15 00:00:00 | +-----------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 month); ``` + ```text +-------------------------------------------------------------+ | month_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -94,9 +102,11 @@ select date_ceil("2023-07-13 22:28:18",interval 5 month); | 2023-12-01 00:00:00 | +-------------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 year); ``` + ```text +------------------------------------------------------------+ | year_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md index 291a32180abfa..9750aaeece3f3 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md @@ -30,7 +30,7 @@ under the License. ## 语法 -`DATE_FLOOR(DATETIME datetime, INTERVAL period type)` +`DATE_FLOOR(, INTERVAL )` ## 参数 @@ -49,6 +49,7 @@ under the License. ```sql select date_floor("0001-01-01 00:00:16",interval 5 second); ``` + ```text +---------------------------------------------------------------+ | second_floor('0001-01-01 00:00:16', 5, '0001-01-01 00:00:00') | @@ -56,9 +57,11 @@ select date_floor("0001-01-01 00:00:16",interval 5 second); | 0001-01-01 00:00:15 | +---------------------------------------------------------------+ ``` + ```sql select date_floor("0001-01-01 00:00:18",interval 5 second); ``` + ```text +---------------------------------------------------------------+ | second_floor('0001-01-01 00:00:18', 5, '0001-01-01 00:00:00') | @@ -66,9 +69,11 @@ select date_floor("0001-01-01 00:00:18",interval 5 second); | 0001-01-01 00:00:15 | +---------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 minute); ``` + ```text +---------------------------------------------------------------+ | minute_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -76,9 +81,11 @@ select date_floor("2023-07-13 22:28:18",interval 5 minute); | 2023-07-13 22:25:00 | +---------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 hour); ``` + ```text +-------------------------------------------------------------+ | hour_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -86,9 +93,11 @@ select date_floor("2023-07-13 22:28:18",interval 5 hour); | 2023-07-13 18:00:00 | +-------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 day); ``` + ```text +------------------------------------------------------------+ | day_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -96,9 +105,11 @@ select date_floor("2023-07-13 22:28:18",interval 5 day); | 2023-07-10 00:00:00 | +------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 month); ``` + ```text +--------------------------------------------------------------+ | month_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -106,9 +117,11 @@ select date_floor("2023-07-13 22:28:18",interval 5 month); | 2023-07-01 00:00:00 | +--------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 year); ``` + ```text +-------------------------------------------------------------+ | year_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md index 5594fdcbf2ed9..6c524ab102168 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md @@ -30,15 +30,14 @@ under the License. ## 语法 -`EXTRACT(unit FROM DATETIME)` +`EXTRACT( FROM )` ## 参数 | 参数 | 说明 | | -- | -- | | `unit` | 提取DATETIME某个指定单位的值。单位可以为year, month, day, hour, minute, second 或者 microsecond | -|`from`| 固定语法 | -| `period` | 参数是合法的日期表达式 | +| `datetime` | 参数是合法的日期表达式 | ## 返回值 @@ -55,6 +54,7 @@ extract(minute from '2022-09-22 17:01:30') as minute, extract(second from '2022-09-22 17:01:30') as second, extract(microsecond from cast('2022-09-22 17:01:30.000123' as datetimev2(6))) as microsecond; ``` + ```text +------+-------+------+------+--------+--------+-------------+ | year | month | day | hour | minute | second | microsecond | diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md index 8ebf0bc6440c8..ab2c2805e75e4 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md @@ -30,7 +30,7 @@ under the License. ## 语法 -`TIMESTAMPADD(unit, interval, DATETIME datetime_expr)` +`TIMESTAMPADD(, , )` ## 参数 @@ -38,7 +38,7 @@ under the License. | -- | -- | | `unit` | 时间单位,指定要添加的时间单位,常见的值有 SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR| |`interval`| 要添加的时间间隔,通常是一个整数,可以是正数或负数,表示添加或减去的时间长度 | -| `DATETIME datetime_expr` | 合法的目标时间戳或日期 | +| `datetime_expr` | 合法的目标时间戳或日期 | ## 返回值 @@ -49,6 +49,7 @@ under the License. ```sql SELECT TIMESTAMPADD(MINUTE,1,'2019-01-02'); ``` + ```text +------------------------------------------------+ | timestampadd(MINUTE, 1, '2019-01-02 00:00:00') | @@ -56,9 +57,11 @@ SELECT TIMESTAMPADD(MINUTE,1,'2019-01-02'); | 2019-01-02 00:01:00 | +------------------------------------------------+ ``` + ```sql SELECT TIMESTAMPADD(WEEK,1,'2019-01-02'); ``` + ```text +----------------------------------------------+ | timestampadd(WEEK, 1, '2019-01-02 00:00:00') | diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md index 5bab33559541d..fce955d991741 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md @@ -30,15 +30,15 @@ under the License. ## 语法 -`TIMESTAMPDIFF(unit, DATETIME datetime_expr1, DATETIME datetime_expr2)` +`TIMESTAMPDIFF(, , )` ## 参数 | 参数 | 说明 | | -- | -- | | `unit` | 时间单位,指定要返回差异的单位,常见的值有 SECOND、MINUTE、HOUR、DAY、MONTH、YEAR 等 | -|`DATETIME datetime_expr1`| 第一个日期时间,合法的目标时间戳或日期 | -|`DATETIME datetime_expr2`| 第二个日期时间,合法的目标时间戳或日期 | +|`datetime_expr1`| 第一个日期时间,合法的目标时间戳或日期 | +|`datetime_expr2`| 第二个日期时间,合法的目标时间戳或日期 | ## 返回值 @@ -49,6 +49,7 @@ under the License. ```sql SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'); ``` + ```text +--------------------------------------------------------------------+ | timestampdiff(MONTH, '2003-02-01 00:00:00', '2003-05-01 00:00:00') | @@ -56,9 +57,11 @@ SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'); | 3 | +--------------------------------------------------------------------+ ``` + ```sql SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01'); ``` + ```text +-------------------------------------------------------------------+ | timestampdiff(YEAR, '2002-05-01 00:00:00', '2001-01-01 00:00:00') | @@ -66,9 +69,11 @@ SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01'); | -1 | +-------------------------------------------------------------------+ ``` + ```sql SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55'); ``` + ```text +---------------------------------------------------------------------+ | timestampdiff(MINUTE, '2003-02-01 00:00:00', '2003-05-01 12:05:55') | diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md index df887d244b64c..b4e040bd2591a 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md @@ -30,7 +30,7 @@ under the License. ## 语法 -`DATE_CEIL(DATETIME datetime, INTERVAL period type)` +`DATE_CEIL(, INTERVAL )` ## 参数 @@ -49,6 +49,7 @@ under the License. ```sql select date_ceil("2023-07-13 22:28:18",interval 5 second); ``` + ```text +--------------------------------------------------------------+ | second_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -56,6 +57,7 @@ select date_ceil("2023-07-13 22:28:18",interval 5 second); | 2023-07-13 22:28:20 | +--------------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 minute); +--------------------------------------------------------------+ @@ -64,9 +66,11 @@ select date_ceil("2023-07-13 22:28:18",interval 5 minute); | 2023-07-13 22:30:00 | +--------------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 hour); ``` + ```text +------------------------------------------------------------+ | hour_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -74,9 +78,11 @@ select date_ceil("2023-07-13 22:28:18",interval 5 hour); | 2023-07-13 23:00:00 | +------------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 day); ``` + ```text +-----------------------------------------------------------+ | day_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -84,9 +90,11 @@ select date_ceil("2023-07-13 22:28:18",interval 5 day); | 2023-07-15 00:00:00 | +-----------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 month); ``` + ```text +-------------------------------------------------------------+ | month_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -94,9 +102,11 @@ select date_ceil("2023-07-13 22:28:18",interval 5 month); | 2023-12-01 00:00:00 | +-------------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 year); ``` + ```text +------------------------------------------------------------+ | year_ceil('2023-07-13 22:28:18', 5, '0001-01-01 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/date-floor.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md index 291a32180abfa..9750aaeece3f3 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md @@ -30,7 +30,7 @@ under the License. ## 语法 -`DATE_FLOOR(DATETIME datetime, INTERVAL period type)` +`DATE_FLOOR(, INTERVAL )` ## 参数 @@ -49,6 +49,7 @@ under the License. ```sql select date_floor("0001-01-01 00:00:16",interval 5 second); ``` + ```text +---------------------------------------------------------------+ | second_floor('0001-01-01 00:00:16', 5, '0001-01-01 00:00:00') | @@ -56,9 +57,11 @@ select date_floor("0001-01-01 00:00:16",interval 5 second); | 0001-01-01 00:00:15 | +---------------------------------------------------------------+ ``` + ```sql select date_floor("0001-01-01 00:00:18",interval 5 second); ``` + ```text +---------------------------------------------------------------+ | second_floor('0001-01-01 00:00:18', 5, '0001-01-01 00:00:00') | @@ -66,9 +69,11 @@ select date_floor("0001-01-01 00:00:18",interval 5 second); | 0001-01-01 00:00:15 | +---------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 minute); ``` + ```text +---------------------------------------------------------------+ | minute_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -76,9 +81,11 @@ select date_floor("2023-07-13 22:28:18",interval 5 minute); | 2023-07-13 22:25:00 | +---------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 hour); ``` + ```text +-------------------------------------------------------------+ | hour_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -86,9 +93,11 @@ select date_floor("2023-07-13 22:28:18",interval 5 hour); | 2023-07-13 18:00:00 | +-------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 day); ``` + ```text +------------------------------------------------------------+ | day_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -96,9 +105,11 @@ select date_floor("2023-07-13 22:28:18",interval 5 day); | 2023-07-10 00:00:00 | +------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 month); ``` + ```text +--------------------------------------------------------------+ | month_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -106,9 +117,11 @@ select date_floor("2023-07-13 22:28:18",interval 5 month); | 2023-07-01 00:00:00 | +--------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 year); ``` + ```text +-------------------------------------------------------------+ | year_floor('2023-07-13 22:28:18', 5, '0001-01-01 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/extract.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md index 5594fdcbf2ed9..6c524ab102168 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md @@ -30,15 +30,14 @@ under the License. ## 语法 -`EXTRACT(unit FROM DATETIME)` +`EXTRACT( FROM )` ## 参数 | 参数 | 说明 | | -- | -- | | `unit` | 提取DATETIME某个指定单位的值。单位可以为year, month, day, hour, minute, second 或者 microsecond | -|`from`| 固定语法 | -| `period` | 参数是合法的日期表达式 | +| `datetime` | 参数是合法的日期表达式 | ## 返回值 @@ -55,6 +54,7 @@ extract(minute from '2022-09-22 17:01:30') as minute, extract(second from '2022-09-22 17:01:30') as second, extract(microsecond from cast('2022-09-22 17:01:30.000123' as datetimev2(6))) as microsecond; ``` + ```text +------+-------+------+------+--------+--------+-------------+ | year | month | day | hour | minute | second | microsecond | diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md index 8ebf0bc6440c8..ab2c2805e75e4 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md @@ -30,7 +30,7 @@ under the License. ## 语法 -`TIMESTAMPADD(unit, interval, DATETIME datetime_expr)` +`TIMESTAMPADD(, , )` ## 参数 @@ -38,7 +38,7 @@ under the License. | -- | -- | | `unit` | 时间单位,指定要添加的时间单位,常见的值有 SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR| |`interval`| 要添加的时间间隔,通常是一个整数,可以是正数或负数,表示添加或减去的时间长度 | -| `DATETIME datetime_expr` | 合法的目标时间戳或日期 | +| `datetime_expr` | 合法的目标时间戳或日期 | ## 返回值 @@ -49,6 +49,7 @@ under the License. ```sql SELECT TIMESTAMPADD(MINUTE,1,'2019-01-02'); ``` + ```text +------------------------------------------------+ | timestampadd(MINUTE, 1, '2019-01-02 00:00:00') | @@ -56,9 +57,11 @@ SELECT TIMESTAMPADD(MINUTE,1,'2019-01-02'); | 2019-01-02 00:01:00 | +------------------------------------------------+ ``` + ```sql SELECT TIMESTAMPADD(WEEK,1,'2019-01-02'); ``` + ```text +----------------------------------------------+ | timestampadd(WEEK, 1, '2019-01-02 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/timestampdiff.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md index 5bab33559541d..fce955d991741 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md @@ -30,15 +30,15 @@ under the License. ## 语法 -`TIMESTAMPDIFF(unit, DATETIME datetime_expr1, DATETIME datetime_expr2)` +`TIMESTAMPDIFF(, , )` ## 参数 | 参数 | 说明 | | -- | -- | | `unit` | 时间单位,指定要返回差异的单位,常见的值有 SECOND、MINUTE、HOUR、DAY、MONTH、YEAR 等 | -|`DATETIME datetime_expr1`| 第一个日期时间,合法的目标时间戳或日期 | -|`DATETIME datetime_expr2`| 第二个日期时间,合法的目标时间戳或日期 | +|`datetime_expr1`| 第一个日期时间,合法的目标时间戳或日期 | +|`datetime_expr2`| 第二个日期时间,合法的目标时间戳或日期 | ## 返回值 @@ -49,6 +49,7 @@ under the License. ```sql SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'); ``` + ```text +--------------------------------------------------------------------+ | timestampdiff(MONTH, '2003-02-01 00:00:00', '2003-05-01 00:00:00') | @@ -56,9 +57,11 @@ SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'); | 3 | +--------------------------------------------------------------------+ ``` + ```sql SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01'); ``` + ```text +-------------------------------------------------------------------+ | timestampdiff(YEAR, '2002-05-01 00:00:00', '2001-01-01 00:00:00') | @@ -66,9 +69,11 @@ SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01'); | -1 | +-------------------------------------------------------------------+ ``` + ```sql SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55'); ``` + ```text +---------------------------------------------------------------------+ | timestampdiff(MINUTE, '2003-02-01 00:00:00', '2003-05-01 12:05:55') | diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md index df887d244b64c..b4e040bd2591a 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md @@ -30,7 +30,7 @@ under the License. ## 语法 -`DATE_CEIL(DATETIME datetime, INTERVAL period type)` +`DATE_CEIL(, INTERVAL )` ## 参数 @@ -49,6 +49,7 @@ under the License. ```sql select date_ceil("2023-07-13 22:28:18",interval 5 second); ``` + ```text +--------------------------------------------------------------+ | second_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -56,6 +57,7 @@ select date_ceil("2023-07-13 22:28:18",interval 5 second); | 2023-07-13 22:28:20 | +--------------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 minute); +--------------------------------------------------------------+ @@ -64,9 +66,11 @@ select date_ceil("2023-07-13 22:28:18",interval 5 minute); | 2023-07-13 22:30:00 | +--------------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 hour); ``` + ```text +------------------------------------------------------------+ | hour_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -74,9 +78,11 @@ select date_ceil("2023-07-13 22:28:18",interval 5 hour); | 2023-07-13 23:00:00 | +------------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 day); ``` + ```text +-----------------------------------------------------------+ | day_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -84,9 +90,11 @@ select date_ceil("2023-07-13 22:28:18",interval 5 day); | 2023-07-15 00:00:00 | +-----------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 month); ``` + ```text +-------------------------------------------------------------+ | month_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -94,9 +102,11 @@ select date_ceil("2023-07-13 22:28:18",interval 5 month); | 2023-12-01 00:00:00 | +-------------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 year); ``` + ```text +------------------------------------------------------------+ | year_ceil('2023-07-13 22:28:18', 5, '0001-01-01 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/date-floor.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md index 291a32180abfa..9750aaeece3f3 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md @@ -30,7 +30,7 @@ under the License. ## 语法 -`DATE_FLOOR(DATETIME datetime, INTERVAL period type)` +`DATE_FLOOR(, INTERVAL )` ## 参数 @@ -49,6 +49,7 @@ under the License. ```sql select date_floor("0001-01-01 00:00:16",interval 5 second); ``` + ```text +---------------------------------------------------------------+ | second_floor('0001-01-01 00:00:16', 5, '0001-01-01 00:00:00') | @@ -56,9 +57,11 @@ select date_floor("0001-01-01 00:00:16",interval 5 second); | 0001-01-01 00:00:15 | +---------------------------------------------------------------+ ``` + ```sql select date_floor("0001-01-01 00:00:18",interval 5 second); ``` + ```text +---------------------------------------------------------------+ | second_floor('0001-01-01 00:00:18', 5, '0001-01-01 00:00:00') | @@ -66,9 +69,11 @@ select date_floor("0001-01-01 00:00:18",interval 5 second); | 0001-01-01 00:00:15 | +---------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 minute); ``` + ```text +---------------------------------------------------------------+ | minute_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -76,9 +81,11 @@ select date_floor("2023-07-13 22:28:18",interval 5 minute); | 2023-07-13 22:25:00 | +---------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 hour); ``` + ```text +-------------------------------------------------------------+ | hour_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -86,9 +93,11 @@ select date_floor("2023-07-13 22:28:18",interval 5 hour); | 2023-07-13 18:00:00 | +-------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 day); ``` + ```text +------------------------------------------------------------+ | day_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -96,9 +105,11 @@ select date_floor("2023-07-13 22:28:18",interval 5 day); | 2023-07-10 00:00:00 | +------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 month); ``` + ```text +--------------------------------------------------------------+ | month_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -106,9 +117,11 @@ select date_floor("2023-07-13 22:28:18",interval 5 month); | 2023-07-01 00:00:00 | +--------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 year); ``` + ```text +-------------------------------------------------------------+ | year_floor('2023-07-13 22:28:18', 5, '0001-01-01 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/extract.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md index 5594fdcbf2ed9..6c524ab102168 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md @@ -30,15 +30,14 @@ under the License. ## 语法 -`EXTRACT(unit FROM DATETIME)` +`EXTRACT( FROM )` ## 参数 | 参数 | 说明 | | -- | -- | | `unit` | 提取DATETIME某个指定单位的值。单位可以为year, month, day, hour, minute, second 或者 microsecond | -|`from`| 固定语法 | -| `period` | 参数是合法的日期表达式 | +| `datetime` | 参数是合法的日期表达式 | ## 返回值 @@ -55,6 +54,7 @@ extract(minute from '2022-09-22 17:01:30') as minute, extract(second from '2022-09-22 17:01:30') as second, extract(microsecond from cast('2022-09-22 17:01:30.000123' as datetimev2(6))) as microsecond; ``` + ```text +------+-------+------+------+--------+--------+-------------+ | year | month | day | hour | minute | second | microsecond | diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md index 8ebf0bc6440c8..ab2c2805e75e4 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md @@ -30,7 +30,7 @@ under the License. ## 语法 -`TIMESTAMPADD(unit, interval, DATETIME datetime_expr)` +`TIMESTAMPADD(, , )` ## 参数 @@ -38,7 +38,7 @@ under the License. | -- | -- | | `unit` | 时间单位,指定要添加的时间单位,常见的值有 SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR| |`interval`| 要添加的时间间隔,通常是一个整数,可以是正数或负数,表示添加或减去的时间长度 | -| `DATETIME datetime_expr` | 合法的目标时间戳或日期 | +| `datetime_expr` | 合法的目标时间戳或日期 | ## 返回值 @@ -49,6 +49,7 @@ under the License. ```sql SELECT TIMESTAMPADD(MINUTE,1,'2019-01-02'); ``` + ```text +------------------------------------------------+ | timestampadd(MINUTE, 1, '2019-01-02 00:00:00') | @@ -56,9 +57,11 @@ SELECT TIMESTAMPADD(MINUTE,1,'2019-01-02'); | 2019-01-02 00:01:00 | +------------------------------------------------+ ``` + ```sql SELECT TIMESTAMPADD(WEEK,1,'2019-01-02'); ``` + ```text +----------------------------------------------+ | timestampadd(WEEK, 1, '2019-01-02 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/timestampdiff.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md index 5bab33559541d..fce955d991741 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md @@ -30,15 +30,15 @@ under the License. ## 语法 -`TIMESTAMPDIFF(unit, DATETIME datetime_expr1, DATETIME datetime_expr2)` +`TIMESTAMPDIFF(, , )` ## 参数 | 参数 | 说明 | | -- | -- | | `unit` | 时间单位,指定要返回差异的单位,常见的值有 SECOND、MINUTE、HOUR、DAY、MONTH、YEAR 等 | -|`DATETIME datetime_expr1`| 第一个日期时间,合法的目标时间戳或日期 | -|`DATETIME datetime_expr2`| 第二个日期时间,合法的目标时间戳或日期 | +|`datetime_expr1`| 第一个日期时间,合法的目标时间戳或日期 | +|`datetime_expr2`| 第二个日期时间,合法的目标时间戳或日期 | ## 返回值 @@ -49,6 +49,7 @@ under the License. ```sql SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'); ``` + ```text +--------------------------------------------------------------------+ | timestampdiff(MONTH, '2003-02-01 00:00:00', '2003-05-01 00:00:00') | @@ -56,9 +57,11 @@ SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'); | 3 | +--------------------------------------------------------------------+ ``` + ```sql SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01'); ``` + ```text +-------------------------------------------------------------------+ | timestampdiff(YEAR, '2002-05-01 00:00:00', '2001-01-01 00:00:00') | @@ -66,9 +69,11 @@ SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01'); | -1 | +-------------------------------------------------------------------+ ``` + ```sql SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55'); ``` + ```text +---------------------------------------------------------------------+ | timestampdiff(MINUTE, '2003-02-01 00:00:00', '2003-05-01 12:05:55') | diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md index d59f6e7d6978b..6cc46d65b69b5 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md @@ -30,7 +30,7 @@ under the License. ## Syntax -`DATE_CEIL(DATETIME datetime, INTERVAL period type)` +`DATE_CEIL(, INTERVAL )` ## Parameters @@ -49,6 +49,7 @@ The return value is a date or time, representing the result of rounding the inpu ```sql select date_ceil("2023-07-13 22:28:18",interval 5 second); ``` + ```text +--------------------------------------------------------------+ | second_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -56,6 +57,7 @@ select date_ceil("2023-07-13 22:28:18",interval 5 second); | 2023-07-13 22:28:20 | +--------------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 minute); +--------------------------------------------------------------+ @@ -64,9 +66,11 @@ select date_ceil("2023-07-13 22:28:18",interval 5 minute); | 2023-07-13 22:30:00 | +--------------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 hour); ``` + ```text +------------------------------------------------------------+ | hour_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -74,9 +78,11 @@ select date_ceil("2023-07-13 22:28:18",interval 5 hour); | 2023-07-13 23:00:00 | +------------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 day); ``` + ```text +-----------------------------------------------------------+ | day_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -84,9 +90,11 @@ select date_ceil("2023-07-13 22:28:18",interval 5 day); | 2023-07-15 00:00:00 | +-----------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 month); ``` + ```text +-------------------------------------------------------------+ | month_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -94,9 +102,11 @@ select date_ceil("2023-07-13 22:28:18",interval 5 month); | 2023-12-01 00:00:00 | +-------------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 year); ``` + ```text +------------------------------------------------------------+ | year_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md index 3841898e3d4d2..98b153bf5dc6c 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md @@ -30,7 +30,7 @@ under the License. ## Syntax -`DATE_FLOOR(DATETIME datetime, INTERVAL period type)` +`DATE_FLOOR(, INTERVAL )` ## Parameters @@ -49,6 +49,7 @@ The return value is a date or time, representing the result of rounding the inpu ```sql select date_floor("0001-01-01 00:00:16",interval 5 second); ``` + ```text +---------------------------------------------------------------+ | second_floor('0001-01-01 00:00:16', 5, '0001-01-01 00:00:00') | @@ -56,9 +57,11 @@ select date_floor("0001-01-01 00:00:16",interval 5 second); | 0001-01-01 00:00:15 | +---------------------------------------------------------------+ ``` + ```sql select date_floor("0001-01-01 00:00:18",interval 5 second); ``` + ```text +---------------------------------------------------------------+ | second_floor('0001-01-01 00:00:18', 5, '0001-01-01 00:00:00') | @@ -66,9 +69,11 @@ select date_floor("0001-01-01 00:00:18",interval 5 second); | 0001-01-01 00:00:15 | +---------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 minute); ``` + ```text +---------------------------------------------------------------+ | minute_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -76,9 +81,11 @@ select date_floor("2023-07-13 22:28:18",interval 5 minute); | 2023-07-13 22:25:00 | +---------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 hour); ``` + ```text +-------------------------------------------------------------+ | hour_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -86,9 +93,11 @@ select date_floor("2023-07-13 22:28:18",interval 5 hour); | 2023-07-13 18:00:00 | +-------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 day); ``` + ```text +------------------------------------------------------------+ | day_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -96,9 +105,11 @@ select date_floor("2023-07-13 22:28:18",interval 5 day); | 2023-07-10 00:00:00 | +------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 month); ``` + ```text +--------------------------------------------------------------+ | month_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -106,9 +117,11 @@ select date_floor("2023-07-13 22:28:18",interval 5 month); | 2023-07-01 00:00:00 | +--------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 year); ``` + ```text +-------------------------------------------------------------+ | year_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md index 8c17aca87b305..8de48ce9cdcba 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md @@ -30,15 +30,14 @@ The `extract` function is used to extract a specified part of a date or time val ## Syntax -`EXTRACT(unit FROM DATETIME)` +`EXTRACT( FROM )` ## Parameters | Parameter | Description | | -- | -- | | `unit` | The unit to extract from the DATETIME. Possible values are year, month, day, hour, minute, second, or microsecond | -| `from` | Fixed syntax | -| `period` | The argument is a valid date expression | +| `datetime` | The argument is a valid date expression | ## Return Value @@ -55,6 +54,7 @@ extract(minute from '2022-09-22 17:01:30') as minute, extract(second from '2022-09-22 17:01:30') as second, extract(microsecond from cast('2022-09-22 17:01:30.000123' as datetimev2(6))) as microsecond; ``` + ```text +------+-------+------+------+--------+--------+-------------+ | year | month | day | hour | minute | second | microsecond | diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md index 3b9f5f09b2ac5..2c0c358c4f6d0 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md @@ -30,7 +30,7 @@ The `timestampadd` function is used to add a specified time unit (such as year, ## Syntax -`TIMESTAMPADD(unit, interval, DATETIME datetime_expr)` +`TIMESTAMPADD(, , )` ## Parameters @@ -38,7 +38,7 @@ The `timestampadd` function is used to add a specified time unit (such as year, | -- | -- | | `unit` | Time unit, specifies the time unit to add, common values include SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR | | `interval` | The time interval to add, typically an integer, which can be positive or negative to add or subtract the time length | -| `DATETIME datetime_expr` | A valid target timestamp or date | +| `datetime_expr` | A valid target timestamp or date | ## Return Value @@ -49,6 +49,7 @@ The return value is the new date and time, representing the result of adding or ```sql SELECT TIMESTAMPADD(MINUTE,1,'2019-01-02'); ``` + ```text +------------------------------------------------+ | timestampadd(MINUTE, 1, '2019-01-02 00:00:00') | @@ -56,9 +57,11 @@ SELECT TIMESTAMPADD(MINUTE,1,'2019-01-02'); | 2019-01-02 00:01:00 | +------------------------------------------------+ ``` + ```sql SELECT TIMESTAMPADD(WEEK,1,'2019-01-02'); ``` + ```text +----------------------------------------------+ | timestampadd(WEEK, 1, '2019-01-02 00:00:00') | diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md index 07aa4f6d8d172..bbabb256ae6e5 100644 --- a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md @@ -30,15 +30,15 @@ The `timestampdiff` function is used to calculate the difference between two tim ## Syntax -`TIMESTAMPDIFF(unit, DATETIME datetime_expr1, DATETIME datetime_expr2)` +`TIMESTAMPDIFF(, , )` ## Parameters | Parameter | Description | | -- | -- | | `unit` | Time unit, specifies the unit in which to return the difference, common values include SECOND, MINUTE, HOUR, DAY, MONTH, YEAR | -| `DATETIME datetime_expr1` | The first datetime, a valid target timestamp or date | -| `DATETIME datetime_expr2` | The second datetime, a valid target timestamp or date | +| `datetime_expr1` | The first datetime, a valid target timestamp or date | +| `datetime_expr2` | The second datetime, a valid target timestamp or date | ## Return Value @@ -49,6 +49,7 @@ The return value is the difference between the two date-times, with the unit det ```sql SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'); ``` + ```text +--------------------------------------------------------------------+ | timestampdiff(MONTH, '2003-02-01 00:00:00', '2003-05-01 00:00:00') | @@ -56,9 +57,11 @@ SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'); | 3 | +--------------------------------------------------------------------+ ``` + ```sql SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01'); ``` + ```text +-------------------------------------------------------------------+ | timestampdiff(YEAR, '2002-05-01 00:00:00', '2001-01-01 00:00:00') | @@ -66,9 +69,11 @@ SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01'); | -1 | +-------------------------------------------------------------------+ ``` + ```sql SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55'); ``` + ```text +---------------------------------------------------------------------+ | timestampdiff(MINUTE, '2003-02-01 00:00:00', '2003-05-01 12:05:55') | diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md index d59f6e7d6978b..6cc46d65b69b5 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-ceil.md @@ -30,7 +30,7 @@ under the License. ## Syntax -`DATE_CEIL(DATETIME datetime, INTERVAL period type)` +`DATE_CEIL(, INTERVAL )` ## Parameters @@ -49,6 +49,7 @@ The return value is a date or time, representing the result of rounding the inpu ```sql select date_ceil("2023-07-13 22:28:18",interval 5 second); ``` + ```text +--------------------------------------------------------------+ | second_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -56,6 +57,7 @@ select date_ceil("2023-07-13 22:28:18",interval 5 second); | 2023-07-13 22:28:20 | +--------------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 minute); +--------------------------------------------------------------+ @@ -64,9 +66,11 @@ select date_ceil("2023-07-13 22:28:18",interval 5 minute); | 2023-07-13 22:30:00 | +--------------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 hour); ``` + ```text +------------------------------------------------------------+ | hour_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -74,9 +78,11 @@ select date_ceil("2023-07-13 22:28:18",interval 5 hour); | 2023-07-13 23:00:00 | +------------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 day); ``` + ```text +-----------------------------------------------------------+ | day_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -84,9 +90,11 @@ select date_ceil("2023-07-13 22:28:18",interval 5 day); | 2023-07-15 00:00:00 | +-----------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 month); ``` + ```text +-------------------------------------------------------------+ | month_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -94,9 +102,11 @@ select date_ceil("2023-07-13 22:28:18",interval 5 month); | 2023-12-01 00:00:00 | +-------------------------------------------------------------+ ``` + ```sql select date_ceil("2023-07-13 22:28:18",interval 5 year); ``` + ```text +------------------------------------------------------------+ | year_ceil('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md index 3841898e3d4d2..98b153bf5dc6c 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/date-floor.md @@ -30,7 +30,7 @@ under the License. ## Syntax -`DATE_FLOOR(DATETIME datetime, INTERVAL period type)` +`DATE_FLOOR(, INTERVAL )` ## Parameters @@ -49,6 +49,7 @@ The return value is a date or time, representing the result of rounding the inpu ```sql select date_floor("0001-01-01 00:00:16",interval 5 second); ``` + ```text +---------------------------------------------------------------+ | second_floor('0001-01-01 00:00:16', 5, '0001-01-01 00:00:00') | @@ -56,9 +57,11 @@ select date_floor("0001-01-01 00:00:16",interval 5 second); | 0001-01-01 00:00:15 | +---------------------------------------------------------------+ ``` + ```sql select date_floor("0001-01-01 00:00:18",interval 5 second); ``` + ```text +---------------------------------------------------------------+ | second_floor('0001-01-01 00:00:18', 5, '0001-01-01 00:00:00') | @@ -66,9 +69,11 @@ select date_floor("0001-01-01 00:00:18",interval 5 second); | 0001-01-01 00:00:15 | +---------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 minute); ``` + ```text +---------------------------------------------------------------+ | minute_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -76,9 +81,11 @@ select date_floor("2023-07-13 22:28:18",interval 5 minute); | 2023-07-13 22:25:00 | +---------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 hour); ``` + ```text +-------------------------------------------------------------+ | hour_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -86,9 +93,11 @@ select date_floor("2023-07-13 22:28:18",interval 5 hour); | 2023-07-13 18:00:00 | +-------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 day); ``` + ```text +------------------------------------------------------------+ | day_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -96,9 +105,11 @@ select date_floor("2023-07-13 22:28:18",interval 5 day); | 2023-07-10 00:00:00 | +------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 month); ``` + ```text +--------------------------------------------------------------+ | month_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | @@ -106,9 +117,11 @@ select date_floor("2023-07-13 22:28:18",interval 5 month); | 2023-07-01 00:00:00 | +--------------------------------------------------------------+ ``` + ```sql select date_floor("2023-07-13 22:28:18",interval 5 year); ``` + ```text +-------------------------------------------------------------+ | year_floor('2023-07-13 22:28:18', 5, '0001-01-01 00:00:00') | diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md index 8c17aca87b305..8de48ce9cdcba 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/extract.md @@ -30,15 +30,14 @@ The `extract` function is used to extract a specified part of a date or time val ## Syntax -`EXTRACT(unit FROM DATETIME)` +`EXTRACT( FROM )` ## Parameters | Parameter | Description | | -- | -- | | `unit` | The unit to extract from the DATETIME. Possible values are year, month, day, hour, minute, second, or microsecond | -| `from` | Fixed syntax | -| `period` | The argument is a valid date expression | +| `datetime` | The argument is a valid date expression | ## Return Value @@ -55,6 +54,7 @@ extract(minute from '2022-09-22 17:01:30') as minute, extract(second from '2022-09-22 17:01:30') as second, extract(microsecond from cast('2022-09-22 17:01:30.000123' as datetimev2(6))) as microsecond; ``` + ```text +------+-------+------+------+--------+--------+-------------+ | year | month | day | hour | minute | second | microsecond | diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md index 3b9f5f09b2ac5..2c0c358c4f6d0 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampadd.md @@ -30,7 +30,7 @@ The `timestampadd` function is used to add a specified time unit (such as year, ## Syntax -`TIMESTAMPADD(unit, interval, DATETIME datetime_expr)` +`TIMESTAMPADD(, , )` ## Parameters @@ -38,7 +38,7 @@ The `timestampadd` function is used to add a specified time unit (such as year, | -- | -- | | `unit` | Time unit, specifies the time unit to add, common values include SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR | | `interval` | The time interval to add, typically an integer, which can be positive or negative to add or subtract the time length | -| `DATETIME datetime_expr` | A valid target timestamp or date | +| `datetime_expr` | A valid target timestamp or date | ## Return Value @@ -49,6 +49,7 @@ The return value is the new date and time, representing the result of adding or ```sql SELECT TIMESTAMPADD(MINUTE,1,'2019-01-02'); ``` + ```text +------------------------------------------------+ | timestampadd(MINUTE, 1, '2019-01-02 00:00:00') | @@ -56,9 +57,11 @@ SELECT TIMESTAMPADD(MINUTE,1,'2019-01-02'); | 2019-01-02 00:01:00 | +------------------------------------------------+ ``` + ```sql SELECT TIMESTAMPADD(WEEK,1,'2019-01-02'); ``` + ```text +----------------------------------------------+ | timestampadd(WEEK, 1, '2019-01-02 00:00:00') | diff --git a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md index 07aa4f6d8d172..bbabb256ae6e5 100644 --- a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md +++ b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/timestampdiff.md @@ -30,15 +30,15 @@ The `timestampdiff` function is used to calculate the difference between two tim ## Syntax -`TIMESTAMPDIFF(unit, DATETIME datetime_expr1, DATETIME datetime_expr2)` +`TIMESTAMPDIFF(, , )` ## Parameters | Parameter | Description | | -- | -- | | `unit` | Time unit, specifies the unit in which to return the difference, common values include SECOND, MINUTE, HOUR, DAY, MONTH, YEAR | -| `DATETIME datetime_expr1` | The first datetime, a valid target timestamp or date | -| `DATETIME datetime_expr2` | The second datetime, a valid target timestamp or date | +| `datetime_expr1` | The first datetime, a valid target timestamp or date | +| `datetime_expr2` | The second datetime, a valid target timestamp or date | ## Return Value @@ -49,6 +49,7 @@ The return value is the difference between the two date-times, with the unit det ```sql SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'); ``` + ```text +--------------------------------------------------------------------+ | timestampdiff(MONTH, '2003-02-01 00:00:00', '2003-05-01 00:00:00') | @@ -56,9 +57,11 @@ SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'); | 3 | +--------------------------------------------------------------------+ ``` + ```sql SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01'); ``` + ```text +-------------------------------------------------------------------+ | timestampdiff(YEAR, '2002-05-01 00:00:00', '2001-01-01 00:00:00') | @@ -66,9 +69,11 @@ SELECT TIMESTAMPDIFF(YEAR,'2002-05-01','2001-01-01'); | -1 | +-------------------------------------------------------------------+ ``` + ```sql SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55'); ``` + ```text +---------------------------------------------------------------------+ | timestampdiff(MINUTE, '2003-02-01 00:00:00', '2003-05-01 12:05:55') |