// dates & times reference

SQL NEXT_DAY function

Returns the first date strictly after the given date that falls on the named weekday.

Категория
Dates & times
Returns
date
In this category
75 of 121

Синтаксис

NEXT_DAY(date, 'DAYNAME')

Поддержка движка

ДвижокSupportЗаметки
SQL Server Not built in No built-in equivalent.
PostgreSQL Not built in No built-in equivalent.
MySQL Not built in No built-in equivalent.
SQLite Not built in No built-in equivalent.
Oracle Да Supported under this name.

Примеры

Oracle

SELECT NEXT_DAY(DATE '2026-08-01', 'MONDAY') FROM dual;  -- 2026-08-03

PostgreSQL

SELECT d + (8 - EXTRACT(ISODOW FROM d)::int) FROM (VALUES (DATE '2026-08-01')) v(d);  -- 2026-08-03

Полезно знать

  • The result is strictly after the input: NEXT_DAY(DATE '2026-08-03', 'MONDAY') with Aug 3 a Monday returns the following week, not today.
  • The weekday string is resolved in the session's NLS_DATE_LANGUAGE: 'LUNES' fails on an English session. Set the session language or use the English name consistently.
  • Time of day is preserved from the input date; TRUNC the input if you want a midnight result.

Questions about NEXT_DAY

How do I find the next Monday in PostgreSQL or MySQL?

PostgreSQL: d + (8 - EXTRACT(ISODOW FROM d)::int) on a date column. MySQL: d + INTERVAL (7 - WEEKDAY(d)) DAY. Both add 1 to 7 days, so a Monday input moves to the following Monday, matching NEXT_DAY.

Does the weekday name depend on language?

Yes, it matches the session's NLS_DATE_LANGUAGE. An English install wants 'MONDAY'; a Spanish one may expect 'LUNES'.

Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.

Cheat sheets for the engines that have it: Oracle.

// fewer lookups

Functions your engine actually has

SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.