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..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 @@ -1,6 +1,6 @@ --- { - "title": "date_ceil", + "title": "DATE_CEIL", "language": "en" } --- @@ -24,83 +24,93 @@ 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(, INTERVAL )` -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) +``` + +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 hour); +``` -mysql [(none)]>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) +``` + +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 year); +``` -mysql [(none)]>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..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 @@ -1,6 +1,6 @@ --- { - "title": "date_floor", + "title": "DATE_FLOOR", "language": "en" } --- @@ -24,91 +24,108 @@ 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(, INTERVAL )` -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) +``` + +```sql +select date_floor("2023-07-13 22:28:18",interval 5 hour); +``` -mysql>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) +``` + +```sql +select date_floor("2023-07-13 22:28:18",interval 5 day); +``` -mysql>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) +``` + +```sql +select date_floor("2023-07-13 22:28:18",interval 5 month); +``` -mysql>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) +``` + +```sql +select date_floor("2023-07-13 22:28:18",interval 5 year); +``` -mysql>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..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 @@ -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( FROM )` +## Parameters + +| Parameter | Description | +| -- | -- | +| `unit` | The unit to extract from the DATETIME. Possible values are year, month, day, hour, minute, second, or microsecond | +| `datetime` | 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..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 @@ -24,35 +24,48 @@ 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(, , )` -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_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. + +## Examples + +```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 | +------------------------------------------------+ +``` + +```sql +SELECT TIMESTAMPADD(WEEK,1,'2019-01-02'); +``` -mysql> 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..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 @@ -24,44 +24,60 @@ 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(, , )` -### 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_expr1` | The first datetime, a valid target timestamp or date | +| `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 + +```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 | +-------------------------------------------------------------------+ +``` +```sql +SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55'); +``` -MySQL> 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..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 @@ -1,6 +1,6 @@ --- { - "title": "date_ceil", + "title": "DATE_CEIL", "language": "zh-CN" } --- @@ -24,83 +24,93 @@ specific language governing permissions and limitations under the License. --> -## date_ceil ## 描述 -**Syntax** -`DATETIME DATE_CEIL(DATETIME datetime, INTERVAL period type)` +`date_ceil` 将日期转化为指定的时间间隔周期的最近上取整时刻。 +## 语法 -将日期转化为指定的时间间隔周期的最近上取整时刻。 +`DATE_CEIL(, INTERVAL )` -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) +``` + +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 hour); +``` -mysql [(none)]>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) +``` + +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 year); +``` -mysql [(none)]>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..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 @@ -1,6 +1,6 @@ --- { - "title": "date_floor", + "title": "DATE_FLOOR", "language": "zh-CN" } --- @@ -24,91 +24,108 @@ specific language governing permissions and limitations under the License. --> -## date_floor ## 描述 -## 语法 -`DATETIME DATE_FLOOR(DATETIME datetime, INTERVAL period type)` +`date_floor` 将日期转化为指定的时间间隔周期的最近下取整时刻。 + +## 语法 +`DATE_FLOOR(, INTERVAL )` -将日期转化为指定的时间间隔周期的最近下取整时刻。 +## 参数 -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) +``` + +```sql +select date_floor("0001-01-01 00:00:18",interval 5 second); +``` -mysql>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) +``` + +```sql +select date_floor("2023-07-13 22:28:18",interval 5 minute); +``` -mysql>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) +``` + +```sql +select date_floor("2023-07-13 22:28:18",interval 5 year); +``` -mysql>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..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 @@ -24,31 +24,41 @@ specific language governing permissions and limitations under the License. --> -## extract ## 描述 + +`extract` 函数用于从日期或时间值中提取指定的部分,如年份、月份、日、小时、分钟、秒等。该函数常用于从日期时间字段中提取具体的时间组件进行计算、比较或展示。 + ## 语法 -`INT extract(unit FROM DATETIME)` +`EXTRACT( FROM )` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `unit` | 提取DATETIME某个指定单位的值。单位可以为year, month, day, hour, minute, second 或者 microsecond | +| `datetime` | 参数是合法的日期表达式 | -提取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..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 @@ -24,36 +24,48 @@ specific language governing permissions and limitations under the License. --> -## timestampadd ## 描述 + +`timestampadd` 函数用于将指定的时间单位(如年、月、日、小时、分钟、秒等)添加到一个时间戳或日期上。这个函数通常用于日期和时间的计算。 + ## 语法 -`DATETIME TIMESTAMPADD(unit, interval, DATETIME datetime_expr)` +`TIMESTAMPADD(, , )` +## 参数 -将整数表达式间隔添加到日期或日期时间表达式datetime_expr中。 +| 参数 | 说明 | +| -- | -- | +| `unit` | 时间单位,指定要添加的时间单位,常见的值有 SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR| +|`interval`| 要添加的时间间隔,通常是一个整数,可以是正数或负数,表示添加或减去的时间长度 | +| `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 | +------------------------------------------------+ +``` + +```sql +SELECT TIMESTAMPADD(WEEK,1,'2019-01-02'); +``` -mysql> 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..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 @@ -24,44 +24,60 @@ specific language governing permissions and limitations under the License. --> -## timestampdiff ## 描述 + +`timestampdiff` 函数用于计算两个时间戳或日期之间的差值,返回两个时间戳之间的时间间隔。可以计算两者之间的差异,以指定的时间单位(如秒、分钟、小时、天、月、年等)返回结果。 + ## 语法 -`INT TIMESTAMPDIFF(unit, DATETIME datetime_expr1, DATETIME datetime_expr2)` +`TIMESTAMPDIFF(, , )` + +## 参数 -返回datetime_expr2−datetime_expr1,其中datetime_expr1和datetime_expr2是日期或日期时间表达式。 +| 参数 | 说明 | +| -- | -- | +| `unit` | 时间单位,指定要返回差异的单位,常见的值有 SECOND、MINUTE、HOUR、DAY、MONTH、YEAR 等 | +|`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 | +-------------------------------------------------------------------+ +``` +```sql +SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55'); +``` -MySQL> 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..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 @@ -1,6 +1,6 @@ --- { - "title": "date_ceil", + "title": "DATE_CEIL", "language": "zh-CN" } --- @@ -24,83 +24,93 @@ specific language governing permissions and limitations under the License. --> -## date_ceil ## 描述 -**Syntax** -`DATETIME DATE_CEIL(DATETIME datetime, INTERVAL period type)` +`date_ceil` 将日期转化为指定的时间间隔周期的最近上取整时刻。 +## 语法 -将日期转化为指定的时间间隔周期的最近上取整时刻。 +`DATE_CEIL(, INTERVAL )` -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) +``` + +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 hour); +``` -mysql [(none)]>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) +``` + +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 year); +``` -mysql [(none)]>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..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 @@ -1,6 +1,6 @@ --- { - "title": "date_floor", + "title": "DATE_FLOOR", "language": "zh-CN" } --- @@ -24,91 +24,108 @@ specific language governing permissions and limitations under the License. --> -## date_floor ## 描述 -## 语法 -`DATETIME DATE_FLOOR(DATETIME datetime, INTERVAL period type)` +`date_floor` 将日期转化为指定的时间间隔周期的最近下取整时刻。 + +## 语法 +`DATE_FLOOR(, INTERVAL )` -将日期转化为指定的时间间隔周期的最近下取整时刻。 +## 参数 -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) +``` + +```sql +select date_floor("0001-01-01 00:00:18",interval 5 second); +``` -mysql>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) +``` + +```sql +select date_floor("2023-07-13 22:28:18",interval 5 minute); +``` -mysql>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) +``` + +```sql +select date_floor("2023-07-13 22:28:18",interval 5 year); +``` -mysql>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..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 @@ -24,31 +24,41 @@ specific language governing permissions and limitations under the License. --> -## extract ## 描述 + +`extract` 函数用于从日期或时间值中提取指定的部分,如年份、月份、日、小时、分钟、秒等。该函数常用于从日期时间字段中提取具体的时间组件进行计算、比较或展示。 + ## 语法 -`INT extract(unit FROM DATETIME)` +`EXTRACT( FROM )` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `unit` | 提取DATETIME某个指定单位的值。单位可以为year, month, day, hour, minute, second 或者 microsecond | +| `datetime` | 参数是合法的日期表达式 | -提取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..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 @@ -24,36 +24,48 @@ specific language governing permissions and limitations under the License. --> -## timestampadd ## 描述 + +`timestampadd` 函数用于将指定的时间单位(如年、月、日、小时、分钟、秒等)添加到一个时间戳或日期上。这个函数通常用于日期和时间的计算。 + ## 语法 -`DATETIME TIMESTAMPADD(unit, interval, DATETIME datetime_expr)` +`TIMESTAMPADD(, , )` +## 参数 -将整数表达式间隔添加到日期或日期时间表达式datetime_expr中。 +| 参数 | 说明 | +| -- | -- | +| `unit` | 时间单位,指定要添加的时间单位,常见的值有 SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR| +|`interval`| 要添加的时间间隔,通常是一个整数,可以是正数或负数,表示添加或减去的时间长度 | +| `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 | +------------------------------------------------+ +``` + +```sql +SELECT TIMESTAMPADD(WEEK,1,'2019-01-02'); +``` -mysql> 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..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 @@ -24,44 +24,60 @@ specific language governing permissions and limitations under the License. --> -## timestampdiff ## 描述 + +`timestampdiff` 函数用于计算两个时间戳或日期之间的差值,返回两个时间戳之间的时间间隔。可以计算两者之间的差异,以指定的时间单位(如秒、分钟、小时、天、月、年等)返回结果。 + ## 语法 -`INT TIMESTAMPDIFF(unit, DATETIME datetime_expr1, DATETIME datetime_expr2)` +`TIMESTAMPDIFF(, , )` + +## 参数 -返回datetime_expr2−datetime_expr1,其中datetime_expr1和datetime_expr2是日期或日期时间表达式。 +| 参数 | 说明 | +| -- | -- | +| `unit` | 时间单位,指定要返回差异的单位,常见的值有 SECOND、MINUTE、HOUR、DAY、MONTH、YEAR 等 | +|`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 | +-------------------------------------------------------------------+ +``` +```sql +SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55'); +``` -MySQL> 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..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 @@ -1,6 +1,6 @@ --- { - "title": "date_ceil", + "title": "DATE_CEIL", "language": "zh-CN" } --- @@ -24,83 +24,93 @@ specific language governing permissions and limitations under the License. --> -## date_ceil ## 描述 -**Syntax** -`DATETIME DATE_CEIL(DATETIME datetime, INTERVAL period type)` +`date_ceil` 将日期转化为指定的时间间隔周期的最近上取整时刻。 +## 语法 -将日期转化为指定的时间间隔周期的最近上取整时刻。 +`DATE_CEIL(, INTERVAL )` -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) +``` + +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 hour); +``` -mysql [(none)]>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) +``` + +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 year); +``` -mysql [(none)]>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..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 @@ -1,6 +1,6 @@ --- { - "title": "date_floor", + "title": "DATE_FLOOR", "language": "zh-CN" } --- @@ -24,91 +24,108 @@ specific language governing permissions and limitations under the License. --> -## date_floor ## 描述 -## 语法 -`DATETIME DATE_FLOOR(DATETIME datetime, INTERVAL period type)` +`date_floor` 将日期转化为指定的时间间隔周期的最近下取整时刻。 + +## 语法 +`DATE_FLOOR(, INTERVAL )` -将日期转化为指定的时间间隔周期的最近下取整时刻。 +## 参数 -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) +``` + +```sql +select date_floor("0001-01-01 00:00:18",interval 5 second); +``` -mysql>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) +``` + +```sql +select date_floor("2023-07-13 22:28:18",interval 5 minute); +``` -mysql>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) +``` + +```sql +select date_floor("2023-07-13 22:28:18",interval 5 year); +``` -mysql>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..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 @@ -24,31 +24,41 @@ specific language governing permissions and limitations under the License. --> -## extract ## 描述 + +`extract` 函数用于从日期或时间值中提取指定的部分,如年份、月份、日、小时、分钟、秒等。该函数常用于从日期时间字段中提取具体的时间组件进行计算、比较或展示。 + ## 语法 -`INT extract(unit FROM DATETIME)` +`EXTRACT( FROM )` + +## 参数 + +| 参数 | 说明 | +| -- | -- | +| `unit` | 提取DATETIME某个指定单位的值。单位可以为year, month, day, hour, minute, second 或者 microsecond | +| `datetime` | 参数是合法的日期表达式 | -提取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..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 @@ -24,36 +24,48 @@ specific language governing permissions and limitations under the License. --> -## timestampadd ## 描述 + +`timestampadd` 函数用于将指定的时间单位(如年、月、日、小时、分钟、秒等)添加到一个时间戳或日期上。这个函数通常用于日期和时间的计算。 + ## 语法 -`DATETIME TIMESTAMPADD(unit, interval, DATETIME datetime_expr)` +`TIMESTAMPADD(, , )` +## 参数 -将整数表达式间隔添加到日期或日期时间表达式datetime_expr中。 +| 参数 | 说明 | +| -- | -- | +| `unit` | 时间单位,指定要添加的时间单位,常见的值有 SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR| +|`interval`| 要添加的时间间隔,通常是一个整数,可以是正数或负数,表示添加或减去的时间长度 | +| `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 | +------------------------------------------------+ +``` + +```sql +SELECT TIMESTAMPADD(WEEK,1,'2019-01-02'); +``` -mysql> 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..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 @@ -24,44 +24,60 @@ specific language governing permissions and limitations under the License. --> -## timestampdiff ## 描述 + +`timestampdiff` 函数用于计算两个时间戳或日期之间的差值,返回两个时间戳之间的时间间隔。可以计算两者之间的差异,以指定的时间单位(如秒、分钟、小时、天、月、年等)返回结果。 + ## 语法 -`INT TIMESTAMPDIFF(unit, DATETIME datetime_expr1, DATETIME datetime_expr2)` +`TIMESTAMPDIFF(, , )` + +## 参数 -返回datetime_expr2−datetime_expr1,其中datetime_expr1和datetime_expr2是日期或日期时间表达式。 +| 参数 | 说明 | +| -- | -- | +| `unit` | 时间单位,指定要返回差异的单位,常见的值有 SECOND、MINUTE、HOUR、DAY、MONTH、YEAR 等 | +|`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 | +-------------------------------------------------------------------+ +``` +```sql +SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55'); +``` -MySQL> 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..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 @@ -1,6 +1,6 @@ --- { - "title": "date_ceil", + "title": "DATE_CEIL", "language": "en" } --- @@ -24,83 +24,93 @@ 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(, INTERVAL )` -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) +``` + +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 hour); +``` -mysql [(none)]>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) +``` + +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 year); +``` -mysql [(none)]>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..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 @@ -1,6 +1,6 @@ --- { - "title": "date_floor", + "title": "DATE_FLOOR", "language": "en" } --- @@ -24,91 +24,108 @@ 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(, INTERVAL )` -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) +``` + +```sql +select date_floor("2023-07-13 22:28:18",interval 5 hour); +``` -mysql>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) +``` + +```sql +select date_floor("2023-07-13 22:28:18",interval 5 day); +``` -mysql>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) +``` + +```sql +select date_floor("2023-07-13 22:28:18",interval 5 month); +``` -mysql>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) +``` + +```sql +select date_floor("2023-07-13 22:28:18",interval 5 year); +``` -mysql>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..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 @@ -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( FROM )` +## Parameters + +| Parameter | Description | +| -- | -- | +| `unit` | The unit to extract from the DATETIME. Possible values are year, month, day, hour, minute, second, or microsecond | +| `datetime` | 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..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 @@ -24,35 +24,48 @@ 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(, , )` -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_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. + +## Examples + +```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 | +------------------------------------------------+ +``` + +```sql +SELECT TIMESTAMPADD(WEEK,1,'2019-01-02'); +``` -mysql> 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..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 @@ -24,44 +24,60 @@ 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(, , )` -### 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_expr1` | The first datetime, a valid target timestamp or date | +| `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 + +```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 | +-------------------------------------------------------------------+ +``` +```sql +SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55'); +``` -MySQL> 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..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 @@ -1,6 +1,6 @@ --- { - "title": "date_ceil", + "title": "DATE_CEIL", "language": "en" } --- @@ -24,83 +24,93 @@ 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(, INTERVAL )` -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) +``` + +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 hour); +``` -mysql [(none)]>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) +``` + +```sql +select date_ceil("2023-07-13 22:28:18",interval 5 year); +``` -mysql [(none)]>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..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 @@ -1,6 +1,6 @@ --- { - "title": "date_floor", + "title": "DATE_FLOOR", "language": "en" } --- @@ -24,91 +24,108 @@ 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(, INTERVAL )` -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) +``` + +```sql +select date_floor("2023-07-13 22:28:18",interval 5 hour); +``` -mysql>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) +``` + +```sql +select date_floor("2023-07-13 22:28:18",interval 5 day); +``` -mysql>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) +``` + +```sql +select date_floor("2023-07-13 22:28:18",interval 5 month); +``` -mysql>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) +``` + +```sql +select date_floor("2023-07-13 22:28:18",interval 5 year); +``` -mysql>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..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 @@ -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( FROM )` +## Parameters + +| Parameter | Description | +| -- | -- | +| `unit` | The unit to extract from the DATETIME. Possible values are year, month, day, hour, minute, second, or microsecond | +| `datetime` | 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..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 @@ -24,35 +24,48 @@ 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(, , )` -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_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. + +## Examples + +```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 | +------------------------------------------------+ +``` + +```sql +SELECT TIMESTAMPADD(WEEK,1,'2019-01-02'); +``` -mysql> 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..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 @@ -24,44 +24,60 @@ 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(, , )` -### 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_expr1` | The first datetime, a valid target timestamp or date | +| `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 + +```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 | +-------------------------------------------------------------------+ +``` +```sql +SELECT TIMESTAMPDIFF(MINUTE,'2003-02-01','2003-05-01 12:05:55'); +``` -MySQL> 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