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 3223c0bd9f8 [Feature](func) Support function PREVIOUS_DAY (#3390)
3223c0bd9f8 is described below

commit 3223c0bd9f844c2cee453914da741e619be56e5f
Author: linrrarity <[email protected]>
AuthorDate: Sun Feb 15 17:07:36 2026 +0800

    [Feature](func) Support function PREVIOUS_DAY (#3390)
    
    ## Versions
    
    - [x] dev
    - [x] 4.x
    - [ ] 3.x
    - [ ] 2.1
    
    ## Languages
    
    - [x] Chinese
    - [x] English
    
    ## Docs Checklist
    
    - [ ] Checked by AI
    - [ ] Test Cases Built
---
 .../date-time-functions/previous-day.md            |  98 ++++++++++++++++++++
 .../date-time-functions/previous-day.md            | 101 ++++++++++++++++++++
 .../date-time-functions/previous-day.md            | 103 +++++++++++++++++++++
 sidebars.ts                                        |   1 +
 .../date-time-functions/previous-day.md            | 102 ++++++++++++++++++++
 versioned_sidebars/version-4.x-sidebars.json       |   1 +
 6 files changed, 406 insertions(+)

diff --git 
a/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/previous-day.md
 
b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/previous-day.md
new file mode 100644
index 00000000000..c8911cff8cf
--- /dev/null
+++ 
b/docs/sql-manual/sql-functions/scalar-functions/date-time-functions/previous-day.md
@@ -0,0 +1,98 @@
+---
+{
+    "title": "PREVIOUS_DAY",
+    "language": "en"
+}
+---
+
+## Description
+
+The PREVIOUS_DAY function returns the first date that matches the target day 
of the week before the specified date. For example, `PREVIOUS_DAY('2020-01-31', 
'MONDAY')` represents the first Monday before 2020-01-31. This function 
supports DATE, DATETIME, and TIMESTAMPTZ types, and ignores the time part of 
the input (calculating based on the date part only).
+
+## Syntax
+
+```sql
+PREVIOUS_DAY(`<date_or_time_expr>`, `<day_of_week>`)
+```
+
+## Parameters
+
+| Parameter             | Description                                          
                                                                                
                                                                                
                                                                                
                                                                                
                                       |
+| --------------------- | 
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 |
+| `<date_or_time_expr>` | Supports DATE/DATETIME types. For specific formats, 
please refer to [TIMESTAMPTZ 
Conversion](../../../../sql-manual/basic-element/sql-data-types/conversion/timestamptz-conversion),
 [DATETIME 
Conversion](../../../../../current/sql-manual/basic-element/sql-data-types/conversion/datetime-conversion)
 and [DATE 
Conversion](../../../../../current/sql-manual/basic-element/sql-data-types/conversion/date-conversion).
 |
+| `<day_of_week>`       | A string expression identifying the day of the week. 
                                                                                
                                                                                
                                                                                
                                                                                
                                       |
+
+`<day_of_week>` must be one of the following values (case-insensitive):
+- 'SU', 'SUN', 'SUNDAY'
+- 'MO', 'MON', 'MONDAY'
+- 'TU', 'TUE', 'TUESDAY'
+- 'WE', 'WED', 'WEDNESDAY'
+- 'TH', 'THU', 'THURSDAY'
+- 'FR', 'FRI', 'FRIDAY'
+- 'SA', 'SAT', 'SATURDAY'
+
+## Return Value
+
+Returns a value of type DATE, representing the first date matching 
`<day_of_week>` before the base date.
+
+Special cases:
+- If the base date itself is the target weekday, returns the target weekday of 
the previous week (not the current date).
+- If `<date_or_time_expr>` is NULL, returns NULL.
+- If `<day_of_week>` is an invalid value (e.g., 'ABC'), throws an exception.
+- If the input is 0000-01-01 (regardless of whether it contains time), returns 
itself (since this date is the minimum valid date, no prior date exists).
+
+## Examples
+
+```sql
+--- The first Monday before the base date
+SELECT PREVIOUS_DAY('2020-01-31', 'MONDAY') AS result;
++------------+
+| result     |
++------------+
+| 2020-01-27 |
++------------+
+
+--- Including time part (time is ignored, calculation based on date only)
+SELECT PREVIOUS_DAY('2020-01-31 02:02:02', 'MON') AS result;
++------------+
+| result     |
++------------+
+| 2020-01-27 |
++------------+
+
+--- The base date itself is the target weekday (returns the previous one)
+SELECT PREVIOUS_DAY('2023-07-17', 'MON') AS result;  -- 2023-07-17 is Monday
++------------+
+| result     |
++------------+
+| 2023-07-10 |
++------------+
+
+--- Target weekday is an abbreviation (case-insensitive)
+SELECT PREVIOUS_DAY('2023-07-13', 'WE') AS result;  -- 2023-07-13 is Thursday
++------------+
+| result     |
++------------+
+| 2023-07-12 |
++------------+
+
+--- Input is NULL (returns NULL)
+SELECT PREVIOUS_DAY(NULL, 'SUN') AS result;
++--------+
+| result |
++--------+
+| NULL   |
++--------+
+
+--- Invalid weekday identifier (throws an exception)
+mysql> SELECT PREVIOUS_DAY('2023-07-13', 'ABC') AS result;
+ERROR 1105 (HY000): errCode = 2, detailMessage = 
(10.16.10.3)[INVALID_ARGUMENT]Function previous_day failed to parse weekday: ABC
+
+--- Minimum date (returns itself)
+SELECT PREVIOUS_DAY('0000-01-01 12:00:00', 'SUNDAY') AS result;
++------------+
+| result     |
++------------+
+| 0000-01-01 |
++------------+
+```
diff --git 
a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/previous-day.md
 
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/previous-day.md
new file mode 100644
index 00000000000..03a07022ccf
--- /dev/null
+++ 
b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/date-time-functions/previous-day.md
@@ -0,0 +1,101 @@
+---
+{
+    "title": "NEXT_DAY",
+    "language": "cn",
+    "description": "NEXTDAY 函数用于返回指定日期之后第一个匹配目标星期几的日期,例如 NEXTDAY('2020-01-31', 
'MONDAY') 表示 2020-01-31 之后的第一个周一。该函数支持处理 DATE、DATETIME 
类型,忽略输入中的时间部分(仅基于日期部分计算)。"
+}
+---
+
+## 描述
+
+NEXT_DAY 函数用于返回指定日期之前第一个匹配目标星期几的日期,例如 NEXT_DAY('2020-01-31', 'MONDAY') 表示 
2020-01-31 前的第一个周一。该函数支持处理 DATE、DATETIME、TIMESTAMPTZ 类型,忽略输入中的时间部分(仅基于日期部分计算)。
+
+## 语法
+
+```sql
+NEXT_DAY(`<date_or_time_expr>`, `<day_of_week>`)
+```
+
+## 参数
+
+| 参数              | 描述                                                         
|
+|-------------------|--------------------------------------------------------------|
+| ``<date_or_time_expr>`` | 支持输入 date/datetime 类型,具体格式请查看 
[timestamptz的转换](../../../../sql-manual/basic-element/sql-data-types/conversion/timestamptz-conversion),[datetime
 
的转换](../../../../../current/sql-manual/basic-element/sql-data-types/conversion/datetime-conversion)
 和 [date 
的转换](../../../../../current/sql-manual/basic-element/sql-data-types/conversion/date-conversion)。
                                 |
+| ``<day_of_week>``   | 用于标识星期几的字符串表达式,为字符串类型。                               |
+
+
+
+``<day_of_week>`` 必须是以下值之一(不区分大小写):
+- 'SU', 'SUN', 'SUNDAY'
+- 'MO', 'MON', 'MONDAY'
+- 'TU', 'TUE', 'TUESDAY'
+- 'WE', 'WED', 'WEDNESDAY'
+- 'TH', 'THU', 'THURSDAY'
+- 'FR', 'FRI', 'FRIDAY'
+- 'SA', 'SAT', 'SATURDAY'
+
+## 返回值
+
+返回类型为 DATE,表示基准日期之前第一个匹配 `<day_of_week>` 的日期。
+
+特殊情况:
+- 若基准日期本身就是目标星期几,返回前目标星期几(而非当前日期);
+- 若 `<date_or_time_expr>` 为 NULL,返回 NULL;
+- 若 `<day_of_week>` 为无效值(如 'ABC'),抛出异常;
+- 若输入为 0000-01-01(无论是否包含时间),返回自身(因该日期是最小有效日期,不存在前置日期);
+
+## 示例
+
+``` sql
+--- 基准日期前第一个星期一
+SELECT PREVIOUS_DAY('2020-01-31', 'MONDAY') AS result;
++------------+
+| result     |
++------------+
+| 2020-01-27 |
++------------+
+
+--- 包含时间部分(忽略时间,仅用日期计算)
+SELECT PREVIOUS_DAY('2020-01-31 02:02:02', 'MON') AS result;
++------------+
+| result     |
++------------+
+| 2020-01-27 |
++------------+
+
+--- 基准日期本身是目标星期几(返回前一个)
+SELECT PREVIOUS_DAY('2023-07-17', 'MON') AS result;  -- 2023-07-17 是星期一
++------------+
+| result     |
++------------+
+| 2023-07-10 |
++------------+
+
+--- 目标星期几为简称(不区分大小写)
+SELECT PREVIOUS_DAY('2023-07-13', 'WE') AS result;  -- 2023-07-13 是星期四
++------------+
+| result     |
++------------+
+| 2023-07-12 |
++------------+
+
+--- 输入为 NULL(返回 NULL)
+SELECT PREVIOUS_DAY(NULL, 'SUN') AS result;
++--------+
+| result |
++--------+
+| NULL   |
++--------+
+
+--- 无效的星期标识(抛出异常)
+mysql> SELECT PREVIOUS_DAY('2023-07-13', 'ABC') AS result;
+ERROR 1105 (HY000): errCode = 2, detailMessage = 
(10.16.10.3)[INVALID_ARGUMENT]Function previous_day failed to parse weekday: ABC
+
+--- 最大日期(返回自身)
+SELECT PREVIOUS_DAY('0000-01-01 12:00:00', 'SUNDAY') AS result;
++------------+
+| result     |
++------------+
+| 0000-01-01 |
++------------+
+``` 
diff --git 
a/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/date-time-functions/previous-day.md
 
b/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/date-time-functions/previous-day.md
new file mode 100644
index 00000000000..9e1930516a9
--- /dev/null
+++ 
b/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/date-time-functions/previous-day.md
@@ -0,0 +1,103 @@
+---
+{
+    "title": "PREVIOUS_DAY",
+    "language": "cn",
+    "description": "PREVIOUS_DAY 函数用于返回指定日期之前第一个匹配目标星期几的日期,例如 
PREVIOUS_DAY('2020-01-31', 'MONDAY') 表示 2020-01-31 前的第一个周一。该函数支持处理 
DATE、DATETIME 类型,忽略输入中的时间部分(仅基于日期部分计算)。"
+}
+---
+
+## 描述
+
+PREVIOUS_DAY 函数用于返回指定日期之前第一个匹配目标星期几的日期,例如 PREVIOUS_DAY('2020-01-31', 'MONDAY') 
表示 2020-01-31 前的第一个周一。该函数支持处理 DATE、DATETIME、TIMESTAMPTZ 
类型,忽略输入中的时间部分(仅基于日期部分计算)。
+
+:::note
+该函数从4.0.4起开始支持
+:::
+
+## 语法
+
+```sql
+PREVIOUS_DAY(`<date_or_time_expr>`, `<day_of_week>`)
+```
+
+## 参数
+
+| 参数                  | 描述                                                     
                                                                                
                                                                                
                                                                                
                                                                             |
+| --------------------- | 
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 |
+| `<date_or_time_expr>` | 支持输入 date/datetime 类型,具体格式请查看 
[timestamptz的转换](../../../../../current/sql-manual/basic-element/sql-data-types/conversion/timestamptz-conversion),[datetime
 
的转换](../../../../../current/sql-manual/basic-element/sql-data-types/conversion/datetime-conversion)
 和 [date 
的转换](../../../../../current/sql-manual/basic-element/sql-data-types/conversion/date-conversion)。
 |
+| `<day_of_week>`       | 用于标识星期几的字符串表达式,为字符串类型。                               
                                                                                
                                                                                
                                                                                
                                                           |
+
+`<day_of_week>` 必须是以下值之一(不区分大小写):
+- 'SU', 'SUN', 'SUNDAY'
+- 'MO', 'MON', 'MONDAY'
+- 'TU', 'TUE', 'TUESDAY'
+- 'WE', 'WED', 'WEDNESDAY'
+- 'TH', 'THU', 'THURSDAY'
+- 'FR', 'FRI', 'FRIDAY'
+- 'SA', 'SAT', 'SATURDAY'
+
+## 返回值
+
+返回类型为 DATE,表示基准日期之前第一个匹配 `<day_of_week>` 的日期。
+
+特殊情况:
+- 若基准日期本身就是目标星期几,返回前目标星期几(而非当前日期);
+- 若 `<date_or_time_expr>` 为 NULL,返回 NULL;
+- 若 `<day_of_week>` 为无效值(如 'ABC'),抛出异常;
+- 若输入为 0000-01-01(无论是否包含时间),返回自身(因该日期是最小有效日期,不存在前置日期);
+
+## 示例
+
+``` sql
+--- 基准日期前第一个星期一
+SELECT PREVIOUS_DAY('2020-01-31', 'MONDAY') AS result;
++------------+
+| result     |
++------------+
+| 2020-01-27 |
++------------+
+
+--- 包含时间部分(忽略时间,仅用日期计算)
+SELECT PREVIOUS_DAY('2020-01-31 02:02:02', 'MON') AS result;
++------------+
+| result     |
++------------+
+| 2020-01-27 |
++------------+
+
+--- 基准日期本身是目标星期几(返回前一个)
+SELECT PREVIOUS_DAY('2023-07-17', 'MON') AS result;  -- 2023-07-17 是星期一
++------------+
+| result     |
++------------+
+| 2023-07-10 |
++------------+
+
+--- 目标星期几为简称(不区分大小写)
+SELECT PREVIOUS_DAY('2023-07-13', 'WE') AS result;  -- 2023-07-13 是星期四
++------------+
+| result     |
++------------+
+| 2023-07-12 |
++------------+
+
+--- 输入为 NULL(返回 NULL)
+SELECT PREVIOUS_DAY(NULL, 'SUN') AS result;
++--------+
+| result |
++--------+
+| NULL   |
++--------+
+
+--- 无效的星期标识(抛出异常)
+mysql> SELECT PREVIOUS_DAY('2023-07-13', 'ABC') AS result;
+ERROR 1105 (HY000): errCode = 2, detailMessage = 
(10.16.10.3)[INVALID_ARGUMENT]Function previous_day failed to parse weekday: ABC
+
+--- 最大日期(返回自身)
+SELECT PREVIOUS_DAY('0000-01-01 12:00:00', 'SUNDAY') AS result;
++------------+
+| result     |
++------------+
+| 0000-01-01 |
++------------+
+```
diff --git a/sidebars.ts b/sidebars.ts
index 99348556d77..718e735d560 100644
--- a/sidebars.ts
+++ b/sidebars.ts
@@ -1486,6 +1486,7 @@ const sidebars: SidebarsConfig = {
                                         
'sql-manual/sql-functions/scalar-functions/date-time-functions/next-day',
                                         
'sql-manual/sql-functions/scalar-functions/date-time-functions/period-add',
                                         
'sql-manual/sql-functions/scalar-functions/date-time-functions/period-diff',
+                                        
'sql-manual/sql-functions/scalar-functions/date-time-functions/previous-day',
                                         
'sql-manual/sql-functions/scalar-functions/date-time-functions/quarter',
                                         
'sql-manual/sql-functions/scalar-functions/date-time-functions/quarters-add',
                                         
'sql-manual/sql-functions/scalar-functions/date-time-functions/quarters-sub',
diff --git 
a/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/date-time-functions/previous-day.md
 
b/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/date-time-functions/previous-day.md
new file mode 100644
index 00000000000..a9e016db0c4
--- /dev/null
+++ 
b/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/date-time-functions/previous-day.md
@@ -0,0 +1,102 @@
+---
+{
+    "title": "PREVIOUS_DAY",
+    "language": "en"
+}
+---
+
+## Description
+
+The PREVIOUS_DAY function returns the first date that matches the target day 
of the week before the specified date. For example, `PREVIOUS_DAY('2020-01-31', 
'MONDAY')` represents the first Monday before 2020-01-31. This function 
supports DATE, DATETIME, and TIMESTAMPTZ types, and ignores the time part of 
the input (calculating based on the date part only).
+
+:::note
+This function has been supported since 4.0.4.
+:::
+
+## Syntax
+
+```sql
+PREVIOUS_DAY(`<date_or_time_expr>`, `<day_of_week>`)
+```
+
+## Parameters
+
+| Parameter             | Description                                          
                                                                                
                                                                                
                                                                                
                                                                                
                                       |
+| --------------------- | 
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 |
+| `<date_or_time_expr>` | Supports DATE/DATETIME types. For specific formats, 
please refer to [TIMESTAMPTZ 
Conversion](../../../../../../docs/sql-manual/basic-element/sql-data-types/conversion/timestamptz-conversion.md),
 [DATETIME 
Conversion](../../../../../current/sql-manual/basic-element/sql-data-types/conversion/datetime-conversion)
 and [DATE 
Conversion](../../../../../current/sql-manual/basic-element/sql-data-types/conversion/date-conversion).
 |
+| `<day_of_week>`       | A string expression identifying the day of the week. 
                                                                                
                                                                                
                                                                                
                                                                                
                                       |
+
+`<day_of_week>` must be one of the following values (case-insensitive):
+- 'SU', 'SUN', 'SUNDAY'
+- 'MO', 'MON', 'MONDAY'
+- 'TU', 'TUE', 'TUESDAY'
+- 'WE', 'WED', 'WEDNESDAY'
+- 'TH', 'THU', 'THURSDAY'
+- 'FR', 'FRI', 'FRIDAY'
+- 'SA', 'SAT', 'SATURDAY'
+
+## Return Value
+
+Returns a value of type DATE, representing the first date matching 
`<day_of_week>` before the base date.
+
+Special cases:
+- If the base date itself is the target weekday, returns the target weekday of 
the previous week (not the current date).
+- If `<date_or_time_expr>` is NULL, returns NULL.
+- If `<day_of_week>` is an invalid value (e.g., 'ABC'), throws an exception.
+- If the input is 0000-01-01 (regardless of whether it contains time), returns 
itself (since this date is the minimum valid date, no prior date exists).
+
+## Examples
+
+```sql
+--- The first Monday before the base date
+SELECT PREVIOUS_DAY('2020-01-31', 'MONDAY') AS result;
++------------+
+| result     |
++------------+
+| 2020-01-27 |
++------------+
+
+--- Including time part (time is ignored, calculation based on date only)
+SELECT PREVIOUS_DAY('2020-01-31 02:02:02', 'MON') AS result;
++------------+
+| result     |
++------------+
+| 2020-01-27 |
++------------+
+
+--- The base date itself is the target weekday (returns the previous one)
+SELECT PREVIOUS_DAY('2023-07-17', 'MON') AS result;  -- 2023-07-17 is Monday
++------------+
+| result     |
++------------+
+| 2023-07-10 |
++------------+
+
+--- Target weekday is an abbreviation (case-insensitive)
+SELECT PREVIOUS_DAY('2023-07-13', 'WE') AS result;  -- 2023-07-13 is Thursday
++------------+
+| result     |
++------------+
+| 2023-07-12 |
++------------+
+
+--- Input is NULL (returns NULL)
+SELECT PREVIOUS_DAY(NULL, 'SUN') AS result;
++--------+
+| result |
++--------+
+| NULL   |
++--------+
+
+--- Invalid weekday identifier (throws an exception)
+mysql> SELECT PREVIOUS_DAY('2023-07-13', 'ABC') AS result;
+ERROR 1105 (HY000): errCode = 2, detailMessage = 
(10.16.10.3)[INVALID_ARGUMENT]Function previous_day failed to parse weekday: ABC
+
+--- Minimum date (returns itself)
+SELECT PREVIOUS_DAY('0000-01-01 12:00:00', 'SUNDAY') AS result;
++------------+
+| result     |
++------------+
+| 0000-01-01 |
++------------+
+```
diff --git a/versioned_sidebars/version-4.x-sidebars.json 
b/versioned_sidebars/version-4.x-sidebars.json
index 7ea076107d2..a37b91bde5b 100644
--- a/versioned_sidebars/version-4.x-sidebars.json
+++ b/versioned_sidebars/version-4.x-sidebars.json
@@ -1500,6 +1500,7 @@
                                         
"sql-manual/sql-functions/scalar-functions/date-time-functions/next-day",
                                         
"sql-manual/sql-functions/scalar-functions/date-time-functions/period-add",
                                         
"sql-manual/sql-functions/scalar-functions/date-time-functions/period-diff",
+                                        
"sql-manual/sql-functions/scalar-functions/date-time-functions/previous-day",
                                         
"sql-manual/sql-functions/scalar-functions/date-time-functions/quarter",
                                         
"sql-manual/sql-functions/scalar-functions/date-time-functions/quarters-add",
                                         
"sql-manual/sql-functions/scalar-functions/date-time-functions/quarters-sub",


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to