This is an automated email from the ASF dual-hosted git repository.
zclll pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris-website.git
The following commit(s) were added to refs/heads/master by this push:
new 3328452372a [doc](fix) fix unix_stamp documention (#2681)
3328452372a is described below
commit 3328452372a661761b8cd5f9f208c3b69b6caf46
Author: dwdwqfwe <[email protected]>
AuthorDate: Thu Jul 31 19:16:59 2025 +0800
[doc](fix) fix unix_stamp documention (#2681)
## Versions
- [x] dev
- [x] 3.0
- [x] 2.1
- [ ] 2.0
## Languages
- [x] Chinese
- [x] English
## Docs Checklist
- [ ] Checked by AI
- [ ] Test Cases Built
---
.../date-time-functions/unix-timestamp.md | 123 +++++++++++++++------
.../date-time-functions/unix-timestamp.md | 109 +++++++++++++-----
.../date-time-functions/unix-timestamp.md | 109 +++++++++++++-----
.../date-time-functions/unix-timestamp.md | 109 +++++++++++++-----
.../date-time-functions/unix-timestamp.md | 123 +++++++++++++++------
.../date-time-functions/unix-timestamp.md | 123 +++++++++++++++------
6 files changed, 513 insertions(+), 183 deletions(-)
diff --git
a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/unix-timestamp.md
b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/unix-timestamp.md
index 90d984ff8d3..0a14a0eff60 100644
---
a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/unix-timestamp.md
+++
b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/unix-timestamp.md
@@ -5,44 +5,61 @@
}
---
-## unix_timestamp
-### Description
-#### Syntax
+## Description
-`INT UNIX_TIMESTAMP([DATETIME date[, STRING fmt]])`
+Converts a Date or Datetime type to a UNIX timestamp.
-`DECIMAL UNIX_TIMESTAMP([DATETIME date[, STRING fmt]])`
+If no argument is provided, it converts the current time to a timestamp.
-Converting a Date or Datetime type to a UNIX timestamp.
+The argument must be of Date or Datetime type.
-If there are no parameters, the current time is converted into a timestamp.
+For the format specification, refer to the format description of the
date_format function.
-The parameter needs to be Date or Datetime type.
+This function is affected by the time zone.
-Any date before 1970-01-01 00:00:00 or after 2038-01-19 03:14:07 will return 0.
+## Sytax
-See `date_format` function to get Format explanation.
+```sql
+UNIX_TIMESTAMP([DATETIME date[, STRING fmt]])
-This function is affected by time zone.
+```
+
+## Parameter
+| Paramters | Description |
+| -- | -- |
+| `<date>` | The datetime value to be converted is of type `datetime` or
`date` type, with a convertible range from '1970-01-01 00:00:01.000000 UTC' to
'3001-01-19 03:14:07.999999 UTC'.|
+| `<fmt>` | The 'date' parameter refers to the specific part that needs to be
converted into a timestamp, and it is a parameter of type string. If this
parameter is provided, only the part matching the format will be converted into
a timestamp. |
-## Return Value
+## Return value
Returns two types based on the input:
-If the input `datetime` and non-zero scale
-Returns a timestamp of type Decimal, maximum six decimal places of precision
-If the input `datetime` and zeo scale
-Returns a timestamp of type `INT`.
-### example
+- If the input `date`(only `datetime` type have the scale not zero) scale is
not 0 or a format parameter is provided,
+returns a timestamp of type Decimal with a maximum precision of six decimal
places.
+- If the input datetime scale is 0 and no format parameter is provided,
+returns a timestamp of type INT.
-```
+- For times before '1970-01-01 00:00:01.000000 UTC' or after '3001-01-19
03:14:07.999999 UTC', the function returns 0.
+
+Returns NULL if any argument is NULL.
+
+## Examples
+
+```sql
+
+-- All the following results are returned in the UTC time zone
+
+set time_zone= 'UTC';
+
+------Displays the timestamp of the current time
mysql> select unix_timestamp();
+------------------+
| unix_timestamp() |
+------------------+
-| 1558589570 |
+| 1753933330 |
+------------------+
+---Input a datetime to display its timestamp
mysql> select unix_timestamp('2007-11-30 10:30:19');
+---------------------------------------+
| unix_timestamp('2007-11-30 10:30:19') |
@@ -50,37 +67,75 @@ mysql> select unix_timestamp('2007-11-30 10:30:19');
| 1196389819 |
+---------------------------------------+
+---Matches the format to display the timestamp corresponding to the given
datetime
mysql> select unix_timestamp('2007-11-30 10:30-19', '%Y-%m-%d %H:%i-%s');
-+---------------------------------------+
-| unix_timestamp('2007-11-30 10:30-19') |
-+---------------------------------------+
-| 1196389819 |
-+---------------------------------------+
++------------------------------------------------------------+
+| unix_timestamp('2007-11-30 10:30-19', '%Y-%m-%d %H:%i-%s') |
++------------------------------------------------------------+
+| 1196389819.000000 |
++------------------------------------------------------------+
+
+
+---Only matches year, month, and day to display the timestamp
+mysql> select unix_timestamp('2007-11-30 10:30%3A19', '%Y-%m-%d');
++-----------------------------------------------------+
+| unix_timestamp('2007-11-30 10:30%3A19', '%Y-%m-%d') |
++-----------------------------------------------------+
+| 1196352000.000000 |
++-----------------------------------------------------+
+
+---Matching with other characters
mysql> select unix_timestamp('2007-11-30 10:30%3A19', '%Y-%m-%d %H:%i%%3A%s');
-+---------------------------------------+
-| unix_timestamp('2007-11-30 10:30%3A19') |
-+---------------------------------------+
-| 1196389819 |
-+---------------------------------------+
++-----------------------------------------------------------------+
+| unix_timestamp('2007-11-30 10:30%3A19', '%Y-%m-%d %H:%i%%3A%s') |
++-----------------------------------------------------------------+
+| 1196389819.000000 |
++-----------------------------------------------------------------+
+
-mysql> select unix_timestamp('1969-01-01 00:00:00');
+---Time beyond the minimum range returns 0
+mysql> SELECT UNIX_TIMESTAMP('1970-01-01 00:00:00');
+---------------------------------------+
-| unix_timestamp('1969-01-01 00:00:00') |
+| UNIX_TIMESTAMP('1970-01-01 00:00:00') |
+---------------------------------------+
| 0 |
+---------------------------------------+
-```
-Input with non-zero scale
-```
+---Input time with non-zero scale
mysql> SELECT UNIX_TIMESTAMP('2015-11-13 10:20:19.123');
+-------------------------------------------+
| UNIX_TIMESTAMP('2015-11-13 10:20:19.123') |
+-------------------------------------------+
| 1447381219.123 |
+-------------------------------------------+
+
+---Exceeding the maximum allowed time range
+
+mysql> SELECT UNIX_TIMESTAMP('3001-01-19 03:14:07.999999');
++----------------------------------------------+
+| UNIX_TIMESTAMP('3001-01-19 03:14:07.999999') |
++----------------------------------------------+
+| 0.000000 |
++----------------------------------------------+
+
+
+---Returns NULL if any argument is NULL
+mysql> select unix_timestamp(NULL);
++----------------------+
+| unix_timestamp(NULL) |
++----------------------+
+| NULL |
++----------------------+
+
+mysql> select unix_timestamp('2038-01-19 11:14:08',null);
++--------------------------------------------+
+| unix_timestamp('2038-01-19 11:14:08',null) |
++--------------------------------------------+
+| NULL |
++--------------------------------------------+
+
```
### keywords
diff --git
a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/unix-timestamp.md
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/unix-timestamp.md
index 25545628fc5..7b9ae167d7e 100644
---
a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/unix-timestamp.md
+++
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/unix-timestamp.md
@@ -5,13 +5,7 @@
}
---
-## unix_timestamp
## 描述
-## 语法
-
-`DECIMAL UNIX_TIMESTAMP([DATETIME date[, STRING fmt]])`
-
-`INT UNIX_TIMESTAMP([DATETIME date[, STRING fmt]])`
将 Date 或者 Datetime 类型转化为 unix 时间戳。
@@ -19,30 +13,53 @@
参数需要是 Date 或者 Datetime 类型。
-对于在 1970-01-01 00:00:00 之前或 2038-01-19 03:14:07 之后的时间,该函数将返回 0。
-
Format 的格式请参阅 `date_format` 函数的格式说明。
该函数受时区影响。
+## 语法
+
+```sql
+UNIX_TIMESTAMP([DATETIME date[, STRING fmt]])
+
+```
+
+## 参数
+
+| 参数 | 描述 |
+| -- | -- |
+| `<date>` | 待转换的日期时间值,类型为 `datetime` 或 `date` 类型,可转换范围为 '1970-01-01
00:00:01.000000 UTC' 至 '3001-01-19 03:14:07.999999 UTC'。|
+| `<fmt>` | date 参数指代需要转换为时间戳的特定部分,其类型为 `string`。若提供该参数,则仅将与格式匹配的部分转换为时间戳。 |
+
## 返回值
根据输入返回两种类型
-1.若是输入的 datetime scale 不为0
+
+1.若是输入的 `date` (只有 datetime 类型才可以有 scale 不为零) scale 不为 0 或者带有 `format` 参数
返回一个时间戳,类型为 Decimal,最高六位小数精度
-2.若是输入的 datetime scale 为0
+2.若是输入的 `date` scale 为 0 并且不带有 `format` 参数
返回一个时间戳,类型为 INT
+对于在 1970-01-01 00:00:01.000000 UTC 之前或 3001-01-19 03:14:07.999999 UTC
之后的时间,该函数将返回 0。
+
+任意参数为 null 则返回 null
+
## 举例
-```
+```sql
+
+---以下都是在 UTC 时区返回的结果
+set time_zone= 'UTC';
+
+---显示当前时间的时间戳
mysql> select unix_timestamp();
+------------------+
| unix_timestamp() |
+------------------+
-| 1558589570 |
+| 1753933330 |
+------------------+
+---输入一个 datetime 显示该时间的
mysql> select unix_timestamp('2007-11-30 10:30:19');
+---------------------------------------+
| unix_timestamp('2007-11-30 10:30:19') |
@@ -50,37 +67,75 @@ mysql> select unix_timestamp('2007-11-30 10:30:19');
| 1196389819 |
+---------------------------------------+
+---匹配 format 显示给出的 datetime 对应时间戳
mysql> select unix_timestamp('2007-11-30 10:30-19', '%Y-%m-%d %H:%i-%s');
-+---------------------------------------+
-| unix_timestamp('2007-11-30 10:30-19') |
-+---------------------------------------+
-| 1196389819 |
-+---------------------------------------+
++------------------------------------------------------------+
+| unix_timestamp('2007-11-30 10:30-19', '%Y-%m-%d %H:%i-%s') |
++------------------------------------------------------------+
+| 1196389819.000000 |
++------------------------------------------------------------+
+
+
+---只匹配年日月显示时间戳
+mysql> select unix_timestamp('2007-11-30 10:30%3A19', '%Y-%m-%d');
++-----------------------------------------------------+
+| unix_timestamp('2007-11-30 10:30%3A19', '%Y-%m-%d') |
++-----------------------------------------------------+
+| 1196352000.000000 |
++-----------------------------------------------------+
+
+---带有其他字符匹配
mysql> select unix_timestamp('2007-11-30 10:30%3A19', '%Y-%m-%d %H:%i%%3A%s');
-+---------------------------------------+
-| unix_timestamp('2007-11-30 10:30%3A19') |
-+---------------------------------------+
-| 1196389819 |
-+---------------------------------------+
++-----------------------------------------------------------------+
+| unix_timestamp('2007-11-30 10:30%3A19', '%Y-%m-%d %H:%i%%3A%s') |
++-----------------------------------------------------------------+
+| 1196389819.000000 |
++-----------------------------------------------------------------+
-mysql> select unix_timestamp('1969-01-01 00:00:00');
+
+---超出最小范围内的时间返回 0
+mysql> SELECT UNIX_TIMESTAMP('1970-01-01 00:00:00');
+---------------------------------------+
-| unix_timestamp('1969-01-01 00:00:00') |
+| UNIX_TIMESTAMP('1970-01-01 00:00:00') |
+---------------------------------------+
| 0 |
+---------------------------------------+
-```
-输入时间并且 scale 不为0
-```
+---输入时间并且 scale 不为 0
mysql> SELECT UNIX_TIMESTAMP('2015-11-13 10:20:19.123');
+-------------------------------------------+
| UNIX_TIMESTAMP('2015-11-13 10:20:19.123') |
+-------------------------------------------+
| 1447381219.123 |
+-------------------------------------------+
+
+---超过允许时间的最大范围
+
+mysql> SELECT UNIX_TIMESTAMP('3001-01-19 03:14:07.999999');
++----------------------------------------------+
+| UNIX_TIMESTAMP('3001-01-19 03:14:07.999999') |
++----------------------------------------------+
+| 0.000000 |
++----------------------------------------------+
+
+
+---任意参数为 null 则返回 Null
+mysql> select unix_timestamp(NULL);
++----------------------+
+| unix_timestamp(NULL) |
++----------------------+
+| NULL |
++----------------------+
+
+mysql> select unix_timestamp('2038-01-19 11:14:08',null);
++--------------------------------------------+
+| unix_timestamp('2038-01-19 11:14:08',null) |
++--------------------------------------------+
+| NULL |
++--------------------------------------------+
+
```
### keywords
diff --git
a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/unix-timestamp.md
b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/unix-timestamp.md
index 25545628fc5..7b9ae167d7e 100644
---
a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/unix-timestamp.md
+++
b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/unix-timestamp.md
@@ -5,13 +5,7 @@
}
---
-## unix_timestamp
## 描述
-## 语法
-
-`DECIMAL UNIX_TIMESTAMP([DATETIME date[, STRING fmt]])`
-
-`INT UNIX_TIMESTAMP([DATETIME date[, STRING fmt]])`
将 Date 或者 Datetime 类型转化为 unix 时间戳。
@@ -19,30 +13,53 @@
参数需要是 Date 或者 Datetime 类型。
-对于在 1970-01-01 00:00:00 之前或 2038-01-19 03:14:07 之后的时间,该函数将返回 0。
-
Format 的格式请参阅 `date_format` 函数的格式说明。
该函数受时区影响。
+## 语法
+
+```sql
+UNIX_TIMESTAMP([DATETIME date[, STRING fmt]])
+
+```
+
+## 参数
+
+| 参数 | 描述 |
+| -- | -- |
+| `<date>` | 待转换的日期时间值,类型为 `datetime` 或 `date` 类型,可转换范围为 '1970-01-01
00:00:01.000000 UTC' 至 '3001-01-19 03:14:07.999999 UTC'。|
+| `<fmt>` | date 参数指代需要转换为时间戳的特定部分,其类型为 `string`。若提供该参数,则仅将与格式匹配的部分转换为时间戳。 |
+
## 返回值
根据输入返回两种类型
-1.若是输入的 datetime scale 不为0
+
+1.若是输入的 `date` (只有 datetime 类型才可以有 scale 不为零) scale 不为 0 或者带有 `format` 参数
返回一个时间戳,类型为 Decimal,最高六位小数精度
-2.若是输入的 datetime scale 为0
+2.若是输入的 `date` scale 为 0 并且不带有 `format` 参数
返回一个时间戳,类型为 INT
+对于在 1970-01-01 00:00:01.000000 UTC 之前或 3001-01-19 03:14:07.999999 UTC
之后的时间,该函数将返回 0。
+
+任意参数为 null 则返回 null
+
## 举例
-```
+```sql
+
+---以下都是在 UTC 时区返回的结果
+set time_zone= 'UTC';
+
+---显示当前时间的时间戳
mysql> select unix_timestamp();
+------------------+
| unix_timestamp() |
+------------------+
-| 1558589570 |
+| 1753933330 |
+------------------+
+---输入一个 datetime 显示该时间的
mysql> select unix_timestamp('2007-11-30 10:30:19');
+---------------------------------------+
| unix_timestamp('2007-11-30 10:30:19') |
@@ -50,37 +67,75 @@ mysql> select unix_timestamp('2007-11-30 10:30:19');
| 1196389819 |
+---------------------------------------+
+---匹配 format 显示给出的 datetime 对应时间戳
mysql> select unix_timestamp('2007-11-30 10:30-19', '%Y-%m-%d %H:%i-%s');
-+---------------------------------------+
-| unix_timestamp('2007-11-30 10:30-19') |
-+---------------------------------------+
-| 1196389819 |
-+---------------------------------------+
++------------------------------------------------------------+
+| unix_timestamp('2007-11-30 10:30-19', '%Y-%m-%d %H:%i-%s') |
++------------------------------------------------------------+
+| 1196389819.000000 |
++------------------------------------------------------------+
+
+
+---只匹配年日月显示时间戳
+mysql> select unix_timestamp('2007-11-30 10:30%3A19', '%Y-%m-%d');
++-----------------------------------------------------+
+| unix_timestamp('2007-11-30 10:30%3A19', '%Y-%m-%d') |
++-----------------------------------------------------+
+| 1196352000.000000 |
++-----------------------------------------------------+
+
+---带有其他字符匹配
mysql> select unix_timestamp('2007-11-30 10:30%3A19', '%Y-%m-%d %H:%i%%3A%s');
-+---------------------------------------+
-| unix_timestamp('2007-11-30 10:30%3A19') |
-+---------------------------------------+
-| 1196389819 |
-+---------------------------------------+
++-----------------------------------------------------------------+
+| unix_timestamp('2007-11-30 10:30%3A19', '%Y-%m-%d %H:%i%%3A%s') |
++-----------------------------------------------------------------+
+| 1196389819.000000 |
++-----------------------------------------------------------------+
-mysql> select unix_timestamp('1969-01-01 00:00:00');
+
+---超出最小范围内的时间返回 0
+mysql> SELECT UNIX_TIMESTAMP('1970-01-01 00:00:00');
+---------------------------------------+
-| unix_timestamp('1969-01-01 00:00:00') |
+| UNIX_TIMESTAMP('1970-01-01 00:00:00') |
+---------------------------------------+
| 0 |
+---------------------------------------+
-```
-输入时间并且 scale 不为0
-```
+---输入时间并且 scale 不为 0
mysql> SELECT UNIX_TIMESTAMP('2015-11-13 10:20:19.123');
+-------------------------------------------+
| UNIX_TIMESTAMP('2015-11-13 10:20:19.123') |
+-------------------------------------------+
| 1447381219.123 |
+-------------------------------------------+
+
+---超过允许时间的最大范围
+
+mysql> SELECT UNIX_TIMESTAMP('3001-01-19 03:14:07.999999');
++----------------------------------------------+
+| UNIX_TIMESTAMP('3001-01-19 03:14:07.999999') |
++----------------------------------------------+
+| 0.000000 |
++----------------------------------------------+
+
+
+---任意参数为 null 则返回 Null
+mysql> select unix_timestamp(NULL);
++----------------------+
+| unix_timestamp(NULL) |
++----------------------+
+| NULL |
++----------------------+
+
+mysql> select unix_timestamp('2038-01-19 11:14:08',null);
++--------------------------------------------+
+| unix_timestamp('2038-01-19 11:14:08',null) |
++--------------------------------------------+
+| NULL |
++--------------------------------------------+
+
```
### keywords
diff --git
a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/unix-timestamp.md
b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/unix-timestamp.md
index 25545628fc5..7b9ae167d7e 100644
---
a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/unix-timestamp.md
+++
b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/unix-timestamp.md
@@ -5,13 +5,7 @@
}
---
-## unix_timestamp
## 描述
-## 语法
-
-`DECIMAL UNIX_TIMESTAMP([DATETIME date[, STRING fmt]])`
-
-`INT UNIX_TIMESTAMP([DATETIME date[, STRING fmt]])`
将 Date 或者 Datetime 类型转化为 unix 时间戳。
@@ -19,30 +13,53 @@
参数需要是 Date 或者 Datetime 类型。
-对于在 1970-01-01 00:00:00 之前或 2038-01-19 03:14:07 之后的时间,该函数将返回 0。
-
Format 的格式请参阅 `date_format` 函数的格式说明。
该函数受时区影响。
+## 语法
+
+```sql
+UNIX_TIMESTAMP([DATETIME date[, STRING fmt]])
+
+```
+
+## 参数
+
+| 参数 | 描述 |
+| -- | -- |
+| `<date>` | 待转换的日期时间值,类型为 `datetime` 或 `date` 类型,可转换范围为 '1970-01-01
00:00:01.000000 UTC' 至 '3001-01-19 03:14:07.999999 UTC'。|
+| `<fmt>` | date 参数指代需要转换为时间戳的特定部分,其类型为 `string`。若提供该参数,则仅将与格式匹配的部分转换为时间戳。 |
+
## 返回值
根据输入返回两种类型
-1.若是输入的 datetime scale 不为0
+
+1.若是输入的 `date` (只有 datetime 类型才可以有 scale 不为零) scale 不为 0 或者带有 `format` 参数
返回一个时间戳,类型为 Decimal,最高六位小数精度
-2.若是输入的 datetime scale 为0
+2.若是输入的 `date` scale 为 0 并且不带有 `format` 参数
返回一个时间戳,类型为 INT
+对于在 1970-01-01 00:00:01.000000 UTC 之前或 3001-01-19 03:14:07.999999 UTC
之后的时间,该函数将返回 0。
+
+任意参数为 null 则返回 null
+
## 举例
-```
+```sql
+
+---以下都是在 UTC 时区返回的结果
+set time_zone= 'UTC';
+
+---显示当前时间的时间戳
mysql> select unix_timestamp();
+------------------+
| unix_timestamp() |
+------------------+
-| 1558589570 |
+| 1753933330 |
+------------------+
+---输入一个 datetime 显示该时间的
mysql> select unix_timestamp('2007-11-30 10:30:19');
+---------------------------------------+
| unix_timestamp('2007-11-30 10:30:19') |
@@ -50,37 +67,75 @@ mysql> select unix_timestamp('2007-11-30 10:30:19');
| 1196389819 |
+---------------------------------------+
+---匹配 format 显示给出的 datetime 对应时间戳
mysql> select unix_timestamp('2007-11-30 10:30-19', '%Y-%m-%d %H:%i-%s');
-+---------------------------------------+
-| unix_timestamp('2007-11-30 10:30-19') |
-+---------------------------------------+
-| 1196389819 |
-+---------------------------------------+
++------------------------------------------------------------+
+| unix_timestamp('2007-11-30 10:30-19', '%Y-%m-%d %H:%i-%s') |
++------------------------------------------------------------+
+| 1196389819.000000 |
++------------------------------------------------------------+
+
+
+---只匹配年日月显示时间戳
+mysql> select unix_timestamp('2007-11-30 10:30%3A19', '%Y-%m-%d');
++-----------------------------------------------------+
+| unix_timestamp('2007-11-30 10:30%3A19', '%Y-%m-%d') |
++-----------------------------------------------------+
+| 1196352000.000000 |
++-----------------------------------------------------+
+
+---带有其他字符匹配
mysql> select unix_timestamp('2007-11-30 10:30%3A19', '%Y-%m-%d %H:%i%%3A%s');
-+---------------------------------------+
-| unix_timestamp('2007-11-30 10:30%3A19') |
-+---------------------------------------+
-| 1196389819 |
-+---------------------------------------+
++-----------------------------------------------------------------+
+| unix_timestamp('2007-11-30 10:30%3A19', '%Y-%m-%d %H:%i%%3A%s') |
++-----------------------------------------------------------------+
+| 1196389819.000000 |
++-----------------------------------------------------------------+
-mysql> select unix_timestamp('1969-01-01 00:00:00');
+
+---超出最小范围内的时间返回 0
+mysql> SELECT UNIX_TIMESTAMP('1970-01-01 00:00:00');
+---------------------------------------+
-| unix_timestamp('1969-01-01 00:00:00') |
+| UNIX_TIMESTAMP('1970-01-01 00:00:00') |
+---------------------------------------+
| 0 |
+---------------------------------------+
-```
-输入时间并且 scale 不为0
-```
+---输入时间并且 scale 不为 0
mysql> SELECT UNIX_TIMESTAMP('2015-11-13 10:20:19.123');
+-------------------------------------------+
| UNIX_TIMESTAMP('2015-11-13 10:20:19.123') |
+-------------------------------------------+
| 1447381219.123 |
+-------------------------------------------+
+
+---超过允许时间的最大范围
+
+mysql> SELECT UNIX_TIMESTAMP('3001-01-19 03:14:07.999999');
++----------------------------------------------+
+| UNIX_TIMESTAMP('3001-01-19 03:14:07.999999') |
++----------------------------------------------+
+| 0.000000 |
++----------------------------------------------+
+
+
+---任意参数为 null 则返回 Null
+mysql> select unix_timestamp(NULL);
++----------------------+
+| unix_timestamp(NULL) |
++----------------------+
+| NULL |
++----------------------+
+
+mysql> select unix_timestamp('2038-01-19 11:14:08',null);
++--------------------------------------------+
+| unix_timestamp('2038-01-19 11:14:08',null) |
++--------------------------------------------+
+| NULL |
++--------------------------------------------+
+
```
### keywords
diff --git
a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/unix-timestamp.md
b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/unix-timestamp.md
index 90d984ff8d3..0a14a0eff60 100644
---
a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/unix-timestamp.md
+++
b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/date-time-functions/unix-timestamp.md
@@ -5,44 +5,61 @@
}
---
-## unix_timestamp
-### Description
-#### Syntax
+## Description
-`INT UNIX_TIMESTAMP([DATETIME date[, STRING fmt]])`
+Converts a Date or Datetime type to a UNIX timestamp.
-`DECIMAL UNIX_TIMESTAMP([DATETIME date[, STRING fmt]])`
+If no argument is provided, it converts the current time to a timestamp.
-Converting a Date or Datetime type to a UNIX timestamp.
+The argument must be of Date or Datetime type.
-If there are no parameters, the current time is converted into a timestamp.
+For the format specification, refer to the format description of the
date_format function.
-The parameter needs to be Date or Datetime type.
+This function is affected by the time zone.
-Any date before 1970-01-01 00:00:00 or after 2038-01-19 03:14:07 will return 0.
+## Sytax
-See `date_format` function to get Format explanation.
+```sql
+UNIX_TIMESTAMP([DATETIME date[, STRING fmt]])
-This function is affected by time zone.
+```
+
+## Parameter
+| Paramters | Description |
+| -- | -- |
+| `<date>` | The datetime value to be converted is of type `datetime` or
`date` type, with a convertible range from '1970-01-01 00:00:01.000000 UTC' to
'3001-01-19 03:14:07.999999 UTC'.|
+| `<fmt>` | The 'date' parameter refers to the specific part that needs to be
converted into a timestamp, and it is a parameter of type string. If this
parameter is provided, only the part matching the format will be converted into
a timestamp. |
-## Return Value
+## Return value
Returns two types based on the input:
-If the input `datetime` and non-zero scale
-Returns a timestamp of type Decimal, maximum six decimal places of precision
-If the input `datetime` and zeo scale
-Returns a timestamp of type `INT`.
-### example
+- If the input `date`(only `datetime` type have the scale not zero) scale is
not 0 or a format parameter is provided,
+returns a timestamp of type Decimal with a maximum precision of six decimal
places.
+- If the input datetime scale is 0 and no format parameter is provided,
+returns a timestamp of type INT.
-```
+- For times before '1970-01-01 00:00:01.000000 UTC' or after '3001-01-19
03:14:07.999999 UTC', the function returns 0.
+
+Returns NULL if any argument is NULL.
+
+## Examples
+
+```sql
+
+-- All the following results are returned in the UTC time zone
+
+set time_zone= 'UTC';
+
+------Displays the timestamp of the current time
mysql> select unix_timestamp();
+------------------+
| unix_timestamp() |
+------------------+
-| 1558589570 |
+| 1753933330 |
+------------------+
+---Input a datetime to display its timestamp
mysql> select unix_timestamp('2007-11-30 10:30:19');
+---------------------------------------+
| unix_timestamp('2007-11-30 10:30:19') |
@@ -50,37 +67,75 @@ mysql> select unix_timestamp('2007-11-30 10:30:19');
| 1196389819 |
+---------------------------------------+
+---Matches the format to display the timestamp corresponding to the given
datetime
mysql> select unix_timestamp('2007-11-30 10:30-19', '%Y-%m-%d %H:%i-%s');
-+---------------------------------------+
-| unix_timestamp('2007-11-30 10:30-19') |
-+---------------------------------------+
-| 1196389819 |
-+---------------------------------------+
++------------------------------------------------------------+
+| unix_timestamp('2007-11-30 10:30-19', '%Y-%m-%d %H:%i-%s') |
++------------------------------------------------------------+
+| 1196389819.000000 |
++------------------------------------------------------------+
+
+
+---Only matches year, month, and day to display the timestamp
+mysql> select unix_timestamp('2007-11-30 10:30%3A19', '%Y-%m-%d');
++-----------------------------------------------------+
+| unix_timestamp('2007-11-30 10:30%3A19', '%Y-%m-%d') |
++-----------------------------------------------------+
+| 1196352000.000000 |
++-----------------------------------------------------+
+
+---Matching with other characters
mysql> select unix_timestamp('2007-11-30 10:30%3A19', '%Y-%m-%d %H:%i%%3A%s');
-+---------------------------------------+
-| unix_timestamp('2007-11-30 10:30%3A19') |
-+---------------------------------------+
-| 1196389819 |
-+---------------------------------------+
++-----------------------------------------------------------------+
+| unix_timestamp('2007-11-30 10:30%3A19', '%Y-%m-%d %H:%i%%3A%s') |
++-----------------------------------------------------------------+
+| 1196389819.000000 |
++-----------------------------------------------------------------+
+
-mysql> select unix_timestamp('1969-01-01 00:00:00');
+---Time beyond the minimum range returns 0
+mysql> SELECT UNIX_TIMESTAMP('1970-01-01 00:00:00');
+---------------------------------------+
-| unix_timestamp('1969-01-01 00:00:00') |
+| UNIX_TIMESTAMP('1970-01-01 00:00:00') |
+---------------------------------------+
| 0 |
+---------------------------------------+
-```
-Input with non-zero scale
-```
+---Input time with non-zero scale
mysql> SELECT UNIX_TIMESTAMP('2015-11-13 10:20:19.123');
+-------------------------------------------+
| UNIX_TIMESTAMP('2015-11-13 10:20:19.123') |
+-------------------------------------------+
| 1447381219.123 |
+-------------------------------------------+
+
+---Exceeding the maximum allowed time range
+
+mysql> SELECT UNIX_TIMESTAMP('3001-01-19 03:14:07.999999');
++----------------------------------------------+
+| UNIX_TIMESTAMP('3001-01-19 03:14:07.999999') |
++----------------------------------------------+
+| 0.000000 |
++----------------------------------------------+
+
+
+---Returns NULL if any argument is NULL
+mysql> select unix_timestamp(NULL);
++----------------------+
+| unix_timestamp(NULL) |
++----------------------+
+| NULL |
++----------------------+
+
+mysql> select unix_timestamp('2038-01-19 11:14:08',null);
++--------------------------------------------+
+| unix_timestamp('2038-01-19 11:14:08',null) |
++--------------------------------------------+
+| NULL |
++--------------------------------------------+
+
```
### keywords
diff --git
a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/unix-timestamp.md
b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/unix-timestamp.md
index 90d984ff8d3..0a14a0eff60 100644
---
a/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/unix-timestamp.md
+++
b/versioned_docs/version-3.0/sql-manual/sql-functions/scalar-functions/date-time-functions/unix-timestamp.md
@@ -5,44 +5,61 @@
}
---
-## unix_timestamp
-### Description
-#### Syntax
+## Description
-`INT UNIX_TIMESTAMP([DATETIME date[, STRING fmt]])`
+Converts a Date or Datetime type to a UNIX timestamp.
-`DECIMAL UNIX_TIMESTAMP([DATETIME date[, STRING fmt]])`
+If no argument is provided, it converts the current time to a timestamp.
-Converting a Date or Datetime type to a UNIX timestamp.
+The argument must be of Date or Datetime type.
-If there are no parameters, the current time is converted into a timestamp.
+For the format specification, refer to the format description of the
date_format function.
-The parameter needs to be Date or Datetime type.
+This function is affected by the time zone.
-Any date before 1970-01-01 00:00:00 or after 2038-01-19 03:14:07 will return 0.
+## Sytax
-See `date_format` function to get Format explanation.
+```sql
+UNIX_TIMESTAMP([DATETIME date[, STRING fmt]])
-This function is affected by time zone.
+```
+
+## Parameter
+| Paramters | Description |
+| -- | -- |
+| `<date>` | The datetime value to be converted is of type `datetime` or
`date` type, with a convertible range from '1970-01-01 00:00:01.000000 UTC' to
'3001-01-19 03:14:07.999999 UTC'.|
+| `<fmt>` | The 'date' parameter refers to the specific part that needs to be
converted into a timestamp, and it is a parameter of type string. If this
parameter is provided, only the part matching the format will be converted into
a timestamp. |
-## Return Value
+## Return value
Returns two types based on the input:
-If the input `datetime` and non-zero scale
-Returns a timestamp of type Decimal, maximum six decimal places of precision
-If the input `datetime` and zeo scale
-Returns a timestamp of type `INT`.
-### example
+- If the input `date`(only `datetime` type have the scale not zero) scale is
not 0 or a format parameter is provided,
+returns a timestamp of type Decimal with a maximum precision of six decimal
places.
+- If the input datetime scale is 0 and no format parameter is provided,
+returns a timestamp of type INT.
-```
+- For times before '1970-01-01 00:00:01.000000 UTC' or after '3001-01-19
03:14:07.999999 UTC', the function returns 0.
+
+Returns NULL if any argument is NULL.
+
+## Examples
+
+```sql
+
+-- All the following results are returned in the UTC time zone
+
+set time_zone= 'UTC';
+
+------Displays the timestamp of the current time
mysql> select unix_timestamp();
+------------------+
| unix_timestamp() |
+------------------+
-| 1558589570 |
+| 1753933330 |
+------------------+
+---Input a datetime to display its timestamp
mysql> select unix_timestamp('2007-11-30 10:30:19');
+---------------------------------------+
| unix_timestamp('2007-11-30 10:30:19') |
@@ -50,37 +67,75 @@ mysql> select unix_timestamp('2007-11-30 10:30:19');
| 1196389819 |
+---------------------------------------+
+---Matches the format to display the timestamp corresponding to the given
datetime
mysql> select unix_timestamp('2007-11-30 10:30-19', '%Y-%m-%d %H:%i-%s');
-+---------------------------------------+
-| unix_timestamp('2007-11-30 10:30-19') |
-+---------------------------------------+
-| 1196389819 |
-+---------------------------------------+
++------------------------------------------------------------+
+| unix_timestamp('2007-11-30 10:30-19', '%Y-%m-%d %H:%i-%s') |
++------------------------------------------------------------+
+| 1196389819.000000 |
++------------------------------------------------------------+
+
+
+---Only matches year, month, and day to display the timestamp
+mysql> select unix_timestamp('2007-11-30 10:30%3A19', '%Y-%m-%d');
++-----------------------------------------------------+
+| unix_timestamp('2007-11-30 10:30%3A19', '%Y-%m-%d') |
++-----------------------------------------------------+
+| 1196352000.000000 |
++-----------------------------------------------------+
+
+---Matching with other characters
mysql> select unix_timestamp('2007-11-30 10:30%3A19', '%Y-%m-%d %H:%i%%3A%s');
-+---------------------------------------+
-| unix_timestamp('2007-11-30 10:30%3A19') |
-+---------------------------------------+
-| 1196389819 |
-+---------------------------------------+
++-----------------------------------------------------------------+
+| unix_timestamp('2007-11-30 10:30%3A19', '%Y-%m-%d %H:%i%%3A%s') |
++-----------------------------------------------------------------+
+| 1196389819.000000 |
++-----------------------------------------------------------------+
+
-mysql> select unix_timestamp('1969-01-01 00:00:00');
+---Time beyond the minimum range returns 0
+mysql> SELECT UNIX_TIMESTAMP('1970-01-01 00:00:00');
+---------------------------------------+
-| unix_timestamp('1969-01-01 00:00:00') |
+| UNIX_TIMESTAMP('1970-01-01 00:00:00') |
+---------------------------------------+
| 0 |
+---------------------------------------+
-```
-Input with non-zero scale
-```
+---Input time with non-zero scale
mysql> SELECT UNIX_TIMESTAMP('2015-11-13 10:20:19.123');
+-------------------------------------------+
| UNIX_TIMESTAMP('2015-11-13 10:20:19.123') |
+-------------------------------------------+
| 1447381219.123 |
+-------------------------------------------+
+
+---Exceeding the maximum allowed time range
+
+mysql> SELECT UNIX_TIMESTAMP('3001-01-19 03:14:07.999999');
++----------------------------------------------+
+| UNIX_TIMESTAMP('3001-01-19 03:14:07.999999') |
++----------------------------------------------+
+| 0.000000 |
++----------------------------------------------+
+
+
+---Returns NULL if any argument is NULL
+mysql> select unix_timestamp(NULL);
++----------------------+
+| unix_timestamp(NULL) |
++----------------------+
+| NULL |
++----------------------+
+
+mysql> select unix_timestamp('2038-01-19 11:14:08',null);
++--------------------------------------------+
+| unix_timestamp('2038-01-19 11:14:08',null) |
++--------------------------------------------+
+| NULL |
++--------------------------------------------+
+
```
### keywords
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]