SQL Server
SELECT EOMONTH(GETDATE());
EOMONTH (2012+) returns a DATE and takes an optional month offset: EOMONTH(GETDATE(), 1) is next month's last day.
Three engines have a named function; PostgreSQL and SQLite make you derive it.
Filed under Types & casting
SQL Server, MySQL and Oracle all have a named function. In PostgreSQL you compose truncate plus an interval, and in SQLite a modifier chain, which is verbose but combines with every other modifier.
The last day of a month depends on the month: 28, 29, 30 or 31. SQL Server, MySQL and Oracle ship a dedicated function; PostgreSQL and SQLite compose one.
SELECT EOMONTH(GETDATE());
EOMONTH (2012+) returns a DATE and takes an optional month offset: EOMONTH(GETDATE(), 1) is next month's last day.
SELECT (DATE_TRUNC('month', NOW()) + INTERVAL '1 month - 1 day')::DATE;
Truncate, step one month forward, one day back; the composed interval '1 month - 1 day' is a single literal with two fields.
SELECT LAST_DAY(CURDATE());
Dedicated LAST_DAY function, returns a DATE, and gracefully returns NULL for invalid input.
SELECT DATE('now', 'start of month', '+1 month', '-1 day');
Chained modifiers read like a sentence: start of this month, forward one, back one day.
SELECT LAST_DAY(SYSDATE) FROM dual;
Dedicated LAST_DAY, keeps the time-of-day of the input, and handles leap years correctly.
Take the last day's day-of-month: DAY(EOMONTH(d)) in SQL Server, EXTRACT(DAY FROM LAST_DAY(d)) in MySQL and Oracle, EXTRACT(DAY FROM DATE_TRUNC('month', d) + INTERVAL '1 month - 1 day') in PostgreSQL, and strftime('%d', DATE(d, 'start of month', '+1 month', '-1 day')) in SQLite.
No, it returns a pure DATE. MySQL's LAST_DAY returns a DATE too, while Oracle's returns a DATE that keeps the input's time of day.
Compare directly: d = EOMONTH(d) in SQL Server, d = LAST_DAY(d) in MySQL and Oracle, d = (DATE_TRUNC('month', d) + INTERVAL '1 month - 1 day')::DATE in PostgreSQL.
A staple of reporting SQL, computed five different ways.
Jan 31 plus one month is Feb 28 in four engines, Mar 3 in SQLite, and an error with Oracle's INTERVAL form.
Grouping by month starts with truncation; MySQL and pre-2022 SQL Server make you build the result by hand.
SQLly is a native SQL workbench for macOS, Windows and Linux. Its formatter and plan viewer work in all five dialects.