Skip to content

Commit 4ab6cf0

Browse files
committed
[Feature](func) Support function UTC_DATE & UTC_TIME
1 parent 1c7aff1 commit 4ab6cf0

File tree

7 files changed

+217
-18
lines changed

7 files changed

+217
-18
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
{
3+
"title": "UTC_DATE",
4+
"language": "en"
5+
}
6+
---
7+
8+
## Description
9+
The UTC_DATE function returns the current date in the UTC timezone. This function is not affected by the local timezone and always returns the current date based on the UTC timezone, ensuring date consistency across different timezone scenarios.
10+
11+
This function behaves consistently with the [utc_date function](https://dev.mysql.com/doc/refman/8.4/en/date-and-time-functions.html#function_utc-date) in MySQL.
12+
13+
## Syntax
14+
15+
```sql
16+
UTC_DATE()
17+
```
18+
19+
## Return Value
20+
Returns the current UTC date, with the type DATE.
21+
22+
According to different usage scenarios, the return type may be of Date type (format: YYYY-MM-DD) or integer type (format: YYYYMMDD).
23+
## Examples
24+
25+
```sql
26+
-- Assume the current local time is UTC+8 2025-10-27 10:55:35
27+
SELECT UTC_DATE(), UTC_DATE() + 0;
28+
```
29+
```text
30+
+------------+----------------+
31+
| UTC_DATE() | UTC_DATE() + 0 |
32+
+------------+----------------+
33+
| 2025-10-27 | 20251027 |
34+
+------------+----------------+
35+
```
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
{
3+
"title": "UTC_TIME",
4+
"language": "en"
5+
}
6+
---
7+
8+
## Description
9+
The UTC_TIME function returns the current time in the UTC timezone. This function is not affected by the local timezone and always returns the current time based on the UTC timezone, ensuring time consistency across different timezone scenarios.
10+
11+
This function behaves consistently with the [utc_time function](https://dev.mysql.com/doc/refman/8.4/en/date-and-time-functions.html#function_utc-time) in MySQL.
12+
13+
## Syntax
14+
15+
```sql
16+
UTC_TIME([<`precision`>])
17+
```
18+
19+
## Parameters
20+
21+
| Parameter | Description |
22+
|-----------|-------------|
23+
| `<precision>` | The precision of the returned time value supports integer types within the range [0, 6]. Only integer type constants are accepted.。 |
24+
25+
## Return Value
26+
Returns the current UTC time.
27+
28+
According to different usage scenarios, the return type may be TIME type (format: HH:mm:ss) or integer type (indicating the time elapsed since 00:00:00, in microseconds).
29+
30+
## Examples
31+
32+
```sql
33+
-- Assume the current local time is UTC+8 2025-10-27 14:39:01
34+
SELECT UTC_TIME(), UTC_TIME() + 1, UTC_TIME(6), UTC_TIME(6) + 1;
35+
```
36+
```text
37+
------------+----------------+-----------------+-----------------+
38+
| UTC_TIME() | UTC_TIME() + 1 | UTC_TIME(6) | UTC_TIME(6) + 1 |
39+
+------------+----------------+-----------------+-----------------+
40+
| 06:39:01 | 23941000001 | 06:39:01.934119 | 23941934120 |
41+
+------------+----------------+-----------------+-----------------+
42+
```
43+
44+
```sql
45+
SELECT UTC_TIME(7);
46+
-- ERROR 1105 (HY000): errCode = 2, detailMessage = scale must be between 0 and 6
47+
```

docs/sql-manual/sql-functions/scalar-functions/date-time-functions/utc-timestamp.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,35 @@ This function behaves consistently with the [utc_timestamp function](https://dev
1313
## Syntax
1414

1515
```sql
16-
UTC_TIMESTAMP()
16+
UTC_TIMESTAMP([`<precision>`])
1717
```
1818

19+
## Parameters
20+
21+
| Parameter | Description |
22+
|-----------|-------------|
23+
| `<precision>` | The precision of the returned date-time value supports integer types within the range [0, 6]. Only integer type constants are accepted.。 |
24+
1925
## Return Value
20-
Returns the current UTC date and time, type DATETIME.
26+
Returns the current UTC date and time.
27+
28+
Depending on the use case, the return type may be a DATETIME type (format: YYYY-MM-DD HH:mm:ss[.ssssss]) or an integer type (format: YYYYMMDDHHmmss, milliseconds will be automatically discarded during type conversion).
2129

2230
## Examples
2331

2432
```sql
25-
-- Current local time is UTC+8 2025-08-14 11:45:42
26-
SELECT UTC_TIMESTAMP() AS utc_str;
27-
+---------------------+
28-
| utc_str |
29-
+---------------------+
30-
| 2025-08-14 03:45:42 |
31-
+---------------------+
33+
-- Current local time is UTC+8 2025-10-27 14:43:21
34+
SELECT UTC_TIMESTAMP(), UTC_TIMESTAMP() + 0, UTC_TIMESTAMP(5), UTC_TIMESTAMP(5) + 0;
35+
```
36+
```text
37+
+---------------------+---------------------+---------------------------+----------------------+
38+
| UTC_TIMESTAMP() | UTC_TIMESTAMP() + 0 | UTC_TIMESTAMP(5) | UTC_TIMESTAMP(5) + 0 |
39+
+---------------------+---------------------+---------------------------+----------------------+
40+
| 2025-10-27 06:43:21 | 20251027064321 | 2025-10-27 06:43:21.88177 | 20251027064321 |
41+
+---------------------+---------------------+---------------------------+----------------------+
42+
```
43+
44+
```sql
45+
SELECT UTC_TIMESTAMP(7);
46+
-- ERROR 1105 (HY000): errCode = 2, detailMessage = scale must be between 0 and 6
3247
```
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
{
3+
"title": "UTC_DATE",
4+
"language": "zh-CN"
5+
}
6+
---
7+
8+
## 描述
9+
UTC_DATE 函数用于返回当前 UTC 时区的日期。该函数不受本地时区影响,始终返回基于 UTC 时区的当前日期,确保跨时区场景下的日期一致性。
10+
11+
该函数与 mysql 中的 [utc_date 函数](https://dev.mysql.com/doc/refman/8.4/en/date-and-time-functions.html#function_utc-date) 行为一致。
12+
13+
## 语法
14+
15+
```sql
16+
UTC_DATE()
17+
```
18+
19+
## 返回值
20+
返回当前 UTC 日期。
21+
22+
根据使用场景的不同,返回类型可能为 Date 类型(格式:YYYY-MM-DD)或整数类型(格式:YYYYMMDD)。
23+
24+
## 举例
25+
26+
```sql
27+
--- 假设当前地区时间为东八区 2025-10-27 10:55:35
28+
SELECT UTC_DATE(), UTC_DATE() + 0;
29+
```
30+
```text
31+
+------------+----------------+
32+
| UTC_DATE() | UTC_DATE() + 0 |
33+
+------------+----------------+
34+
| 2025-10-27 | 20251027 |
35+
+------------+----------------+
36+
```
37+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
{
3+
"title": "UTC_TIME",
4+
"language": "zh-CN"
5+
}
6+
---
7+
8+
## 描述
9+
UTC_TIME 函数用于返回当前 UTC 时区的时间。该函数不受本地时区影响,始终返回基于 UTC 时区的当前时间,确保跨时区场景下的时间一致性。
10+
11+
该函数与 mysql 中的 [utc_time 函数](https://dev.mysql.com/doc/refman/8.4/en/date-and-time-functions.html#function_utc-time) 行为一致。
12+
13+
## 语法
14+
15+
```sql
16+
UTC_TIME([<`precision`>])
17+
```
18+
19+
## 参数
20+
21+
| 参数 | 描述 |
22+
|----------------------------|-----------------------------|
23+
| `<precision>` | 返回的时间值的精度,支持[0, 6]范围内的整数类型。仅接受整数类型常量。 |
24+
25+
## 返回值
26+
27+
返回当前 UTC 时间。
28+
29+
根据使用场景的不同,返回类型可能为 TIME 类型(格式:HH:mm:ss)或整数类型(表示从 00:00:00 开始经过的时间值,单位为微秒)。
30+
31+
## 举例
32+
33+
```sql
34+
--- 假设当前地区时间为东八区 2025-10-27 14:39:01
35+
SELECT UTC_TIME(), UTC_TIME() + 1, UTC_TIME(6), UTC_TIME(6) + 1;
36+
```
37+
```text
38+
------------+----------------+-----------------+-----------------+
39+
| UTC_TIME() | UTC_TIME() + 1 | UTC_TIME(6) | UTC_TIME(6) + 1 |
40+
+------------+----------------+-----------------+-----------------+
41+
| 06:39:01 | 23941000001 | 06:39:01.934119 | 23941934120 |
42+
+------------+----------------+-----------------+-----------------+
43+
```
44+
45+
```sql
46+
SELECT UTC_TIME(7);
47+
-- ERROR 1105 (HY000): errCode = 2, detailMessage = scale must be between 0 and 6
48+
```

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

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,37 @@ UTC_TIMESTAMP 函数用于返回当前 UTC 时区在所的日期时间。该函
1313
## 语法
1414

1515
```sql
16-
UTC_TIMESTAMP()
16+
UTC_TIMESTAMP([`<precision>`])
1717
```
1818

19+
## 参数
20+
21+
| 参数 | 描述 |
22+
|----------------------------|-----------------------------|
23+
| `<precision>` | 返回的时间值的精度,支持[0, 6]范围内的整数类型。仅接受整数类型常量。 |
24+
1925
## 返回值
20-
返回当前 UTC 日期时间,类型为 DATETIME.
26+
返回当前 UTC 日期时间.
27+
28+
根据使用场景的不同,返回类型可能为 DATETIME 类型(格式:YYYY-MM-DD HH:mm:ss[.ssssss])或整数类型(格式:YYYYMMDDHHmmss, 在类型转换时,会自动丢弃毫秒数)。
29+
2130

2231
## 举例
2332

2433
```sql
34+
---当前地区时间为东八区 2025-10-27 14:43:21
35+
SELECT UTC_TIMESTAMP(), UTC_TIMESTAMP() + 0, UTC_TIMESTAMP(5), UTC_TIMESTAMP(5) + 0;
36+
```
37+
```text
38+
+---------------------+---------------------+---------------------------+----------------------+
39+
| UTC_TIMESTAMP() | UTC_TIMESTAMP() + 0 | UTC_TIMESTAMP(5) | UTC_TIMESTAMP(5) + 0 |
40+
+---------------------+---------------------+---------------------------+----------------------+
41+
| 2025-10-27 06:43:21 | 20251027064321 | 2025-10-27 06:43:21.88177 | 20251027064321 |
42+
+---------------------+---------------------+---------------------------+----------------------+
43+
```
2544

26-
---当前地区时间为东八区 2025-08-14 11:45:42
27-
SELECT UTC_TIMESTAMP() AS utc_str;
28-
+---------------------+
29-
| utc_str |
30-
+---------------------+
31-
| 2025-08-14 03:45:42 |
32-
+---------------------+
45+
```sql
46+
SELECT UTC_TIMESTAMP(7);
47+
-- ERROR 1105 (HY000): errCode = 2, detailMessage = scale must be between 0 and 6
3348
```
3449

sidebars.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,8 @@
14191419
"sql-manual/sql-functions/scalar-functions/date-time-functions/to-days",
14201420
"sql-manual/sql-functions/scalar-functions/date-time-functions/to-iso8601",
14211421
"sql-manual/sql-functions/scalar-functions/date-time-functions/to-monday",
1422+
"sql-manual/sql-functions/scalar-functions/date-time-functions/utc-date",
1423+
"sql-manual/sql-functions/scalar-functions/date-time-functions/utc-time",
14221424
"sql-manual/sql-functions/scalar-functions/date-time-functions/utc-timestamp",
14231425
"sql-manual/sql-functions/scalar-functions/date-time-functions/unix-timestamp",
14241426
"sql-manual/sql-functions/scalar-functions/date-time-functions/week",

0 commit comments

Comments
 (0)