Back to Library

EOMONTH() in SQL

Returns the last day of the month for a specified date with an optional month offset.

Syntax

EOMONTH(date_expression [, month_offset])
Return type
DATE

EOMONTH() Function Example

SELECT EOMONTH(order_date) FROM orders;
-- Output: 2024-12-31 (last day of the month for given date)

What is EOMONTH() in SQL?

The EOMONTH() function in SQL returns the last day of the month for a given date, with an optional month offset. It is commonly used for financial calculations, reporting, and determining month-end deadlines.

This function is primarily supported in SQL Server. For other databases:

  • MySQL & PostgreSQL: Use LAST_DAY(date_column).

  • Oracle: Uses LAST_DAY(date_column).

  • SQLite: Uses strftime('%Y-%m-%d', date_column, 'start of month', '+1 month', '-1 day').

Parameters:

  • date_expression: Date, datetime, or timestamp value

  • month_offset (optional): Number of months to offset (-12 to 12)

Example Use Cases:

-- Get end of current month

SELECT EOMONTH(GETDATE()) AS month_end;
-- Output:
month_end
---------
2024-12-31

-- Get end of next month

SELECT EOMONTH(order_date, 1) FROM orders;
-- Output:
order_date     next_month_end
-----------    --------------
2024-12-15     2025-01-31
2024-11-20     2024-12-31
2024-10-05     2024-11-30
2024-09-25     2024-10-31
2024-08-10     2024-09-30

-- Find last day transactions

SELECT * FROM transactions WHERE transaction_date = EOMONTH(transaction_date);
-- Output:
transaction_id    transaction_date    amount    status
--------------    ----------------    ------    -------
T101             2024-12-31          567.89    Complete
T102             2024-11-30          789.12    Pending
T103             2024-10-31          456.78    Complete
T104             2024-09-30          678.90    Complete
T105             2024-08-31          890.12    Complete

Notes:

  • Behavior: Returns NULL if input is NULL

  • Performance Considerations: May impact index usage

  • Version Info: Not available in all DBMS versions

  • Deprecated/Recommended Alternatives: Some DBMS use LAST_DAY()

Error Handling:

  • Error: Returns NULL for invalid dates

  • Recommendation: Validate date format before using function

Supported Databases:

DBMS
Function / Syntax
Example
Behavior with NULL
MySQL

LAST_DAY()

LAST_DAY(date)

Returns NULL

PostgreSQL

DATE_TRUNC('MONTH', date) + INTERVAL '1 MONTH - 1 day'

DATE_TRUNC('MONTH', '2024-12-15') + INTERVAL '1 MONTH - 1 day'

Returns NULL

SQL Server

EOMONTH()

EOMONTH(date, [offset])

Returns NULL

SQLite

date(date, 'start of month', '+1 month', '-1 day')

date('2024-12-15', 'start of month', '+1 month', '-1 day')

Returns NULL

BigQuery

LAST_DAY()

LAST_DAY(date)

Returns NULL

Snowflake

LAST_DAY() or EOMONTH()LAST_DAY()

LAST_DAY(date)

Returns NULL

Athena

LAST_DAY()

LAST_DAY(date)

Returns NULL

Related Functions:

DATEFROMPARTS()

Creates a date value from specified year, month, and day integers.

Creates a date value from specified year, month, and day integers.

Creates a date value from specified year, month, and day integers.

Creates a date value from specified year, month, and day integers.

DATEFORMAT()

Converts a date/timestamp expression into a specified string format.

Converts a date/timestamp expression into a specified string format.

Converts a date/timestamp expression into a specified string format.

Converts a date/timestamp expression into a specified string format.

EOMONTH()

Returns the last day of the month for a specified date with an optional month offset.

Returns the last day of the month for a specified date with an optional month offset.

Returns the last day of the month for a specified date with an optional month offset.

Returns the last day of the month for a specified date with an optional month offset.

DAY()

Extracts the day of the month (1-31) from a date or timestamp expression.

Extracts the day of the month (1-31) from a date or timestamp expression.

Extracts the day of the month (1-31) from a date or timestamp expression.

Extracts the day of the month (1-31) from a date or timestamp expression.

YEAR()

Extracts the year value from a date or timestamp expression.

Extracts the year value from a date or timestamp expression.

Extracts the year value from a date or timestamp expression.

Extracts the year value from a date or timestamp expression.

GETDATE()

Returns the current date and time of the database server.

Returns the current date and time of the database server.

Returns the current date and time of the database server.

Returns the current date and time of the database server.

One place for all your queries,
directly on your SQL editor