Skip to content

Commit 8737d19

Browse files
authored
[docs](from-unixtime) add fractional timestamp support documentation (#3543)
- Document support for DECIMAL type input timestamps with fractional seconds - Update parameter description to indicate BIGINT or DECIMAL type support - Extend supported timestamp range to include microsecond precision (253402271999.999999) - Add three examples demonstrating fractional timestamp conversion with sub-second precision ## Versions - [x] dev - [x] 4.x - [ ] 3.x - [ ] 2.1 ## Languages - [x] Chinese - [x] English ## Docs Checklist - [x] Checked by AI - [ ] Test Cases Built
1 parent 906492e commit 8737d19

4 files changed

Lines changed: 112 additions & 16 deletions

File tree

  • docs/sql-manual/sql-functions/scalar-functions/date-time-functions
  • i18n/zh-CN/docusaurus-plugin-content-docs
    • current/sql-manual/sql-functions/scalar-functions/date-time-functions
    • version-4.x/sql-manual/sql-functions/scalar-functions/date-time-functions
  • versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/date-time-functions

docs/sql-manual/sql-functions/scalar-functions/date-time-functions/from-unixtime.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
## Description
1010

1111

12-
The FROM_UNIXTIME function is used to convert a Unix timestamp (in seconds) to a date-time string or VARCHAR type value in a specified format. The reference time for Unix timestamps is 1970-01-01 00:00:00 UTC, and the function generates the corresponding date-time representation based on the input timestamp and format string.
12+
The FROM_UNIXTIME function is used to convert a Unix timestamp (in seconds) to a date-time string or VARCHAR type value in a specified format. The reference time for Unix timestamps is 1970-01-01 00:00:00 UTC, and the function generates the corresponding date-time representation based on the input timestamp and format string. When the input timestamp contains a fractional part, the result includes sub-second precision up to microseconds (6 decimal places).
1313

1414
This function is consistent with the [from_unixtime function](https://dev.mysql.com/doc/refman/8.4/en/date-and-time-functions.html#function_from-unixtime) in MySQL.
1515

@@ -23,13 +23,13 @@ FROM_UNIXTIME(<unix_timestamp> [, <string_format>])
2323

2424
| Parameter | Description |
2525
| -- | -- |
26-
| `<unix_timestamp>` | Input Unix timestamp, of integer type BIGINT, representing the number of seconds from 1970-01-01 00:00:00 UTC |
26+
| `<unix_timestamp>` | Input Unix timestamp, of type BIGINT or DECIMAL, representing the number of seconds (with optional fractional seconds) from 1970-01-01 00:00:00 UTC |
2727
| `<string_format>` | Format string, supports varchar and string types, default is %Y-%m-%d %H:%i:%s. For specific formats, please refer to [date-format](./date-format) |
2828

2929
## Return Value
3030

31-
Returns date in specified format, of type VARCHAR, returning the result of converting the UTC timezone unix timestamp to the current timezone time.
32-
- Currently supported unix_timestamp range is [0, 253402271999] corresponding to dates from 1970-01-01 00:00:00 to 9999-12-31 23:59:59, unix_timestamp outside this range will return an error
31+
Returns date in specified format, of type VARCHAR, returning the result of converting the UTC timezone unix timestamp to the current timezone time. When the input contains a fractional part, the result includes sub-second precision (e.g., `2007-12-01 00:30:19.500000`).
32+
- Currently supported unix_timestamp range is [0, 253402271999.999999] corresponding to dates from 1970-01-01 00:00:00 to 9999-12-31 23:59:59.999999, unix_timestamp outside this range will return an error
3333
- If string_format is invalid, returns a string that does not meet expectations.
3434
- If any parameter is NULL, returns NULL
3535
- If the format length is over 128 characters, returns error
@@ -95,6 +95,30 @@ mysql> select from_unixtime(32536799,"gdaskpdp");
9595
| gdaskpdp |
9696
+------------------------------------+
9797

98+
---Fractional timestamp input, result includes sub-second precision
99+
mysql> select from_unixtime(1196440219.5);
100+
+-----------------------------+
101+
| from_unixtime(1196440219.5) |
102+
+-----------------------------+
103+
| 2007-12-01 00:30:19.500000 |
104+
+-----------------------------+
105+
106+
---Fractional timestamp with microsecond precision
107+
mysql> select from_unixtime(1196440219.123456);
108+
+----------------------------------+
109+
| from_unixtime(1196440219.123456) |
110+
+----------------------------------+
111+
| 2007-12-01 00:30:19.123456 |
112+
+----------------------------------+
113+
114+
---Use %f format specifier to display microseconds explicitly
115+
mysql> select from_unixtime(1196440219.123456, '%Y-%m-%d %H:%i:%s.%f');
116+
+----------------------------------------------------------+
117+
| from_unixtime(1196440219.123456, '%Y-%m-%d %H:%i:%s.%f') |
118+
+----------------------------------------------------------+
119+
| 2007-12-01 00:30:19.123456 |
120+
+----------------------------------------------------------+
121+
98122
---Input is NULL, returns NULL
99123
mysql> select from_unixtime(NULL);
100124
+---------------------+

i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/from-unixtime.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
## 描述
1010

11-
FROM_UNIXTIME 函数用于将 Unix 时间戳(以秒为单位) 转换为指定格式的日期时间字符串或 VARCHAR 类型值。Unix 时间戳的基准时间为 1970-01-01 00:00:00 UTC,函数会根据输入的时间戳和格式字符串,生成对应的日期时间表示。
11+
FROM_UNIXTIME 函数用于将 Unix 时间戳(以秒为单位) 转换为指定格式的日期时间字符串或 VARCHAR 类型值。Unix 时间戳的基准时间为 1970-01-01 00:00:00 UTC,函数会根据输入的时间戳和格式字符串,生成对应的日期时间表示。当输入的时间戳包含小数部分时,结果将包含最多微秒精度(6 位小数)的亚秒部分。
1212

1313
该函数与 mysql 中的 [from_unixtime 函数](https://dev.mysql.com/doc/refman/8.4/en/date-and-time-functions.html#function_from-unixtime) 行为一致
1414

@@ -22,13 +22,13 @@ FROM_UNIXTIME(<unix_timestamp> [, <string_format>])
2222

2323
| 参数 | 说明 |
2424
| -- | -- |
25-
| `<unix_timestamp>` | 输入的 Unix 时间戳,类型为整数 BIGINT,表示从 1970-01-01 00:00:00 UTC 开始的秒数 |
25+
| `<unix_timestamp>` | 输入的 Unix 时间戳,类型为 BIGINT 或 DECIMAL,表示从 1970-01-01 00:00:00 UTC 开始的秒数(可包含小数秒) |
2626
| `<string_format>` | format 格式,支持类型 varchar 和 string,默认为 %Y-%m-%d %H:%i:%s,具体格式请查看 [date-format](./date-format)|
2727

2828
## 返回值
2929

30-
返回指定格式的日期,类型为 VARCHAR,返回的是 UTC 时区下的时间戳的时间戳转换为当前时区的时间
31-
- 目前支持的 unix_timestamp 范围为 [0,253402271999] 对应日期为 1970-01-01 00:00:00 至 9999-12-31 23:59:59,超出范围的 unix_timestamp 将返回错误
30+
返回指定格式的日期,类型为 VARCHAR,返回的是 UTC 时区下的时间戳转换为当前时区的时间。当输入包含小数部分时,结果包含亚秒精度(如 `2007-12-01 00:30:19.500000`
31+
- 目前支持的 unix_timestamp 范围为 [0,253402271999.999999] 对应日期为 1970-01-01 00:00:00 至 9999-12-31 23:59:59.999999,超出范围的 unix_timestamp 将返回错误
3232
- 若 string_format 格式无效,返回不符合预期的字符串。
3333
- 若任意参数为 NULL,则返回 NULL
3434
- 如果 string_format 超过 128 字符长度,返回错误
@@ -93,6 +93,30 @@ mysql> select from_unixtime(32536799,"gdaskpdp");
9393
| gdaskpdp |
9494
+------------------------------------+
9595

96+
---小数时间戳输入,结果包含亚秒精度
97+
mysql> select from_unixtime(1196440219.5);
98+
+-----------------------------+
99+
| from_unixtime(1196440219.5) |
100+
+-----------------------------+
101+
| 2007-12-01 00:30:19.500000 |
102+
+-----------------------------+
103+
104+
---小数时间戳,微秒精度
105+
mysql> select from_unixtime(1196440219.123456);
106+
+----------------------------------+
107+
| from_unixtime(1196440219.123456) |
108+
+----------------------------------+
109+
| 2007-12-01 00:30:19.123456 |
110+
+----------------------------------+
111+
112+
---使用 %f 格式符显式输出微秒部分
113+
mysql> select from_unixtime(1196440219.123456, '%Y-%m-%d %H:%i:%s.%f');
114+
+----------------------------------------------------------+
115+
| from_unixtime(1196440219.123456, '%Y-%m-%d %H:%i:%s.%f') |
116+
+----------------------------------------------------------+
117+
| 2007-12-01 00:30:19.123456 |
118+
+----------------------------------------------------------+
119+
96120
---输入为 NULL,返回 NULL
97121
mysql> select from_unixtime(NULL);
98122
+---------------------+

i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/date-time-functions/from-unixtime.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
## 描述
1010

11-
FROM_UNIXTIME 函数用于将 Unix 时间戳(以秒为单位) 转换为指定格式的日期时间字符串或 VARCHAR 类型值。Unix 时间戳的基准时间为 1970-01-01 00:00:00 UTC,函数会根据输入的时间戳和格式字符串,生成对应的日期时间表示。
11+
FROM_UNIXTIME 函数用于将 Unix 时间戳(以秒为单位) 转换为指定格式的日期时间字符串或 VARCHAR 类型值。Unix 时间戳的基准时间为 1970-01-01 00:00:00 UTC,函数会根据输入的时间戳和格式字符串,生成对应的日期时间表示。当输入的时间戳包含小数部分时,结果将包含最多微秒精度(6 位小数)的亚秒部分。
1212

1313
该函数与 mysql 中的 [from_unixtime 函数](https://dev.mysql.com/doc/refman/8.4/en/date-and-time-functions.html#function_from-unixtime) 行为一致
1414

@@ -22,13 +22,13 @@ FROM_UNIXTIME(<unix_timestamp> [, <string_format>])
2222

2323
| 参数 | 说明 |
2424
| -- | -- |
25-
| `<unix_timestamp>` | 输入的 Unix 时间戳,类型为整数 BIGINT,表示从 1970-01-01 00:00:00 UTC 开始的秒数 |
25+
| `<unix_timestamp>` | 输入的 Unix 时间戳,类型为 BIGINT 或 DECIMAL,表示从 1970-01-01 00:00:00 UTC 开始的秒数(可包含小数秒) |
2626
| `<string_format>` | format 格式,支持类型 varchar 和 string,默认为 %Y-%m-%d %H:%i:%s,具体格式请查看 [date-format](./date-format)|
2727

2828
## 返回值
2929

30-
返回指定格式的日期,类型为 VARCHAR,返回的是 UTC 时区下的时间戳的时间戳转换为当前时区的时间
31-
- 目前支持的 unix_timestamp 范围为 [0,253402271999] 对应日期为 1970-01-01 00:00:00 至 9999-12-31 23:59:59,超出范围的 unix_timestamp 将返回错误
30+
返回指定格式的日期,类型为 VARCHAR,返回的是 UTC 时区下的时间戳转换为当前时区的时间。当输入包含小数部分时,结果包含亚秒精度(如 `2007-12-01 00:30:19.500000`
31+
- 目前支持的 unix_timestamp 范围为 [0,253402271999.999999] 对应日期为 1970-01-01 00:00:00 至 9999-12-31 23:59:59.999999,超出范围的 unix_timestamp 将返回错误
3232
- 若 string_format 格式无效,返回不符合预期的字符串。
3333
- 若任意参数为 NULL,则返回 NULL
3434
- 如果 string_format 超过 128 字符长度,返回错误
@@ -93,6 +93,30 @@ mysql> select from_unixtime(32536799,"gdaskpdp");
9393
| gdaskpdp |
9494
+------------------------------------+
9595

96+
---小数时间戳输入,结果包含亚秒精度
97+
mysql> select from_unixtime(1196440219.5);
98+
+-----------------------------+
99+
| from_unixtime(1196440219.5) |
100+
+-----------------------------+
101+
| 2007-12-01 00:30:19.500000 |
102+
+-----------------------------+
103+
104+
---小数时间戳,微秒精度
105+
mysql> select from_unixtime(1196440219.123456);
106+
+----------------------------------+
107+
| from_unixtime(1196440219.123456) |
108+
+----------------------------------+
109+
| 2007-12-01 00:30:19.123456 |
110+
+----------------------------------+
111+
112+
---使用 %f 格式符显式输出微秒部分
113+
mysql> select from_unixtime(1196440219.123456, '%Y-%m-%d %H:%i:%s.%f');
114+
+----------------------------------------------------------+
115+
| from_unixtime(1196440219.123456, '%Y-%m-%d %H:%i:%s.%f') |
116+
+----------------------------------------------------------+
117+
| 2007-12-01 00:30:19.123456 |
118+
+----------------------------------------------------------+
119+
96120
---输入为 NULL,返回 NULL
97121
mysql> select from_unixtime(NULL);
98122
+---------------------+

versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/date-time-functions/from-unixtime.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
## Description
1010

1111

12-
The FROM_UNIXTIME function is used to convert a Unix timestamp (in seconds) to a date-time string or VARCHAR type value in a specified format. The reference time for Unix timestamps is 1970-01-01 00:00:00 UTC, and the function generates the corresponding date-time representation based on the input timestamp and format string.
12+
The FROM_UNIXTIME function is used to convert a Unix timestamp (in seconds) to a date-time string or VARCHAR type value in a specified format. The reference time for Unix timestamps is 1970-01-01 00:00:00 UTC, and the function generates the corresponding date-time representation based on the input timestamp and format string. When the input timestamp contains a fractional part, the result includes sub-second precision up to microseconds (6 decimal places).
1313

1414
This function is consistent with the [from_unixtime function](https://dev.mysql.com/doc/refman/8.4/en/date-and-time-functions.html#function_from-unixtime) in MySQL.
1515

@@ -23,13 +23,13 @@ FROM_UNIXTIME(<unix_timestamp> [, <string_format>])
2323

2424
| Parameter | Description |
2525
| -- | -- |
26-
| `<unix_timestamp>` | Input Unix timestamp, of integer type BIGINT, representing the number of seconds from 1970-01-01 00:00:00 UTC |
26+
| `<unix_timestamp>` | Input Unix timestamp, of type BIGINT or DECIMAL, representing the number of seconds (with optional fractional seconds) from 1970-01-01 00:00:00 UTC |
2727
| `<string_format>` | Format string, supports varchar and string types, default is %Y-%m-%d %H:%i:%s. For specific formats, please refer to [date-format](./date-format) |
2828

2929
## Return Value
3030

31-
Returns date in specified format, of type VARCHAR, returning the result of converting the UTC timezone unix timestamp to the current timezone time.
32-
- Currently supported unix_timestamp range is [0, 253402271999] corresponding to dates from 1970-01-01 00:00:00 to 9999-12-31 23:59:59, unix_timestamp outside this range will return an error
31+
Returns date in specified format, of type VARCHAR, returning the result of converting the UTC timezone unix timestamp to the current timezone time. When the input contains a fractional part, the result includes sub-second precision (e.g., `2007-12-01 00:30:19.500000`).
32+
- Currently supported unix_timestamp range is [0, 253402271999.999999] corresponding to dates from 1970-01-01 00:00:00 to 9999-12-31 23:59:59.999999, unix_timestamp outside this range will return an error
3333
- If string_format is invalid, returns a string that does not meet expectations.
3434
- If any parameter is NULL, returns NULL
3535
- If the format length is over 128 characters, returns error
@@ -95,6 +95,30 @@ mysql> select from_unixtime(32536799,"gdaskpdp");
9595
| gdaskpdp |
9696
+------------------------------------+
9797

98+
---Fractional timestamp input, result includes sub-second precision
99+
mysql> select from_unixtime(1196440219.5);
100+
+-----------------------------+
101+
| from_unixtime(1196440219.5) |
102+
+-----------------------------+
103+
| 2007-12-01 00:30:19.500000 |
104+
+-----------------------------+
105+
106+
---Fractional timestamp with microsecond precision
107+
mysql> select from_unixtime(1196440219.123456);
108+
+----------------------------------+
109+
| from_unixtime(1196440219.123456) |
110+
+----------------------------------+
111+
| 2007-12-01 00:30:19.123456 |
112+
+----------------------------------+
113+
114+
---Use %f format specifier to display microseconds explicitly
115+
mysql> select from_unixtime(1196440219.123456, '%Y-%m-%d %H:%i:%s.%f');
116+
+----------------------------------------------------------+
117+
| from_unixtime(1196440219.123456, '%Y-%m-%d %H:%i:%s.%f') |
118+
+----------------------------------------------------------+
119+
| 2007-12-01 00:30:19.123456 |
120+
+----------------------------------------------------------+
121+
98122
---Input is NULL, returns NULL
99123
mysql> select from_unixtime(NULL);
100124
+---------------------+

0 commit comments

Comments
 (0)