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.months (
Operand|int) – Optional. The number of months to offset from the month of date. Can be a scalar or array. Defaults to 0.
- 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.
- 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)
``date`` — accepted types
DATE
DATETIME
DATETIME_ARRAY
DATE_ARRAY
``months`` — accepted types
DECIMAL
DECIMAL_ARRAY
INTEGER
INTEGER_ARRAY
Return types
DATE
DATE_ARRAY