next_day
返回输入日期 (DATE 或 DATETIME) 之后出现的第一个指定的星期几 (DOW) 的日期。例如,next_day('2023-04-06', 'Monday')
返回 '2023-04-06' 之后出现的下一个星期一的日期。
此函数从 v3.1 开始支持。它与 previous_day 相反。
语法
DATE next_day(DATETIME|DATE date_expr, VARCHAR dow)
参数
-
date_expr
:输入日期。它必须是有效的 DATE 或 DATETIME 表达式。 -
dow
:星期几。有效值包括多个缩写,区分大小写DOW_FULL DOW_2 DOW_3 星期日 Su Sun 星期一 Mo Mon Tuesday Tu Tue Wednesday We Wed Thursday Th Thu Friday Fr Fri Saturday Sa Sat
返回值
返回 DATE 值。
任何无效的 dow
都会导致错误。dow
区分大小写。
如果传入无效日期或 NULL 参数,则返回 NULL。
示例
-- Return the date of the next Monday that occurred after 2023-04-06. 2023-04-06 is Thursday and the date of the next Monday is 2023-04-10.
MySQL > select next_day('2023-04-06', 'Monday');
+----------------------------------+
| next_day('2023-04-06', 'Monday') |
+----------------------------------+
| 2023-04-10 |
+----------------------------------+
MySQL > select next_day('2023-04-06', 'Tue');
+-------------------------------+
| next_day('2023-04-06', 'Tue') |
+-------------------------------+
| 2023-04-11 |
+-------------------------------+
MySQL > select next_day('2023-04-06 20:13:14', 'Fr');
+---------------------------------------+
| next_day('2023-04-06 20:13:14', 'Fr') |
+---------------------------------------+
| 2023-04-07 |
+---------------------------------------+
关键词
NEXT_DAY, NEXT