EOMONTH
- EOMONTH(date, months=0)[source]
Returns the last day of the month for a given date, optionally offset by a number of months.
The EOMONTH function calculates the end-of-month date based on the input date. You can shift the resulting date forward or backward using the months parameter. If months is positive, the end-of-month moves forward; if negative, it moves backward. If either input is an array, the function operates element-wise.
- Parameters:
date (
Operand) –The starting date from which the end-of-month is calculated.
Supported types:
DATE
DATETIME
DATE_ARRAY
DATETIME_ARRAY
months (
Operand|int) –Optional. The number of months to offset from the month of date. Can be a scalar or array. Defaults to 0.
Supported types:
INTEGER
DECIMAL
INTEGER_ARRAY
DECIMAL_ARRAY
- Return type:
- Returns:
The end-of-month date after applying the month offset. The result has the same shape (scalar or array) as the inputs.
Supported types:
DATE
DATE_ARRAY
- Raises:
ValueError – If date is not a date/datetime type, or if months is not numeric.
Examples
Basic usage:
EOMONTH(DATE(2024, 1, 15)) # Returns DATE(2024, 1, 31)
Offset by 2 months:
EOMONTH(DATE(2024, 1, 15), 2) # Returns DATE(2024, 3, 31)
Negative offset:
EOMONTH(DATE(2024, 1, 15), -1) # Returns DATE(2023, 12, 31)