// dates & times reference

SQL EOMONTH function

Returns the last day of the month containing the input, shifted by a whole number of months if asked.

Categoría
Dates & times
Returns
date
In this category
89 of 121

Sintaxis

EOMONTH(date [, months_to_add])

Soporte del motor

MotorSupportNotas
SQL Server Sí Supported under this name.
PostgreSQL Different name or syntax date_trunc('month', d) + INTERVAL '1 month -1 day'
MySQL Different name or syntax LAST_DAY(d)
SQLite Different name or syntax date(d, 'start of month', '+1 month', '-1 day')
Oracle Different name or syntax LAST_DAY(d)

Ejemplos

SQL Server

SELECT EOMONTH('2026-08-15');  -- 2026-08-31

SQL Server

SELECT EOMONTH('2026-08-15', -1);  -- 2026-07-31

PostgreSQL

SELECT (date_trunc('month', DATE '2026-08-15') + INTERVAL '1 month -1 day')::date;

Conviene saberlo

  • The second argument is months, not days: EOMONTH('2026-08-15', -1) is July 31, 2026, the tidy way to get prior month-end for balances.
  • EOMONTH returns the date type, with no time part even for datetime input; DATEADD(DAY, 1, EOMONTH(d)) is the first of the next month.
  • It needs SQL Server 2012 or later. MySQL's LAST_DAY dates back to 4.1 and Oracle's is older still; neither takes a month offset.

Questions about EOMONTH

EOMONTH vs LAST_DAY?

They answer the same question; LAST_DAY exists in MySQL and Oracle, EOMONTH in SQL Server. The offset argument is EOMONTH's extra; LAST_DAY callers add DATE_ADD themselves.

How do I get the last *weekday* of the month?

No function does it. Step back from EOMONTH: subtract 1 day when it falls on a Saturday and 2 on a Sunday, testing DATEPART(WEEKDAY, ...) with SET DATEFIRST in mind.

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

// 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.