LAST_DAY_OF()
All functions > DATE AND TIME > LAST_DAY_OF()
Returns the last calendar day of the period containing the given date or timestamp, as midnight on that day.
Signatures
Returns: Midnight TIMESTAMP on the last day of the period
LAST_DAY_OF(date: DATE | TIMESTAMP, unit: VARCHAR) → TIMESTAMP sql
| Parameter | Type | Required | Description |
|---|---|---|---|
date | `DATE | TIMESTAMP` | Yes |
unit | VARCHAR | Yes | Period name: WEEK, MONTH, QUARTER, HALF, or YEAR (case-insensitive when provided as a literal) |
Notes
unitmust be one of: WEEK, MONTH, QUARTER, HALF, YEAR (recognized case-insensitively after trimming whitespace)- Week uses the same week boundaries as
DATE_TRUNC(..., 'week')(Monday–Sunday) - Half means January–June vs July–December (last day is June 30 or December 31)
- Non-literal
unitvalues are evaluated at runtime; unknown values surface as an execution error - Returns NULL if
dateorunitis NULL
Examples
FeatureQL
SELECT
f1 := LAST_DAY_OF(TIMESTAMP '2024-03-20 15:00:00', 'MONTH'), -- End of March
f2 := LAST_DAY_OF(TIMESTAMP '2024-03-20 12:00:00', 'WEEK'), -- ISO week containing 20 Mar 2024 ends Sunday
f3 := LAST_DAY_OF(TIMESTAMP '2024-02-10 00:00:00', 'QUARTER'), -- End of Q1
f4 := LAST_DAY_OF(TIMESTAMP '2024-05-01 00:00:00', 'HALF'), -- End of first half-year
f5 := LAST_DAY_OF(TIMESTAMP '2024-09-01 00:00:00', 'HALF'), -- End of second half-year
f6 := LAST_DAY_OF(TIMESTAMP '2024-07-04 00:00:00', 'YEAR') -- End of calendar year
;Result
| f1 TIMESTAMP | f2 TIMESTAMP | f3 TIMESTAMP | f4 TIMESTAMP | f5 TIMESTAMP | f6 TIMESTAMP |
|---|---|---|---|---|---|
| 2024-03-31 | 2024-03-24 | 2024-03-31 | 2024-06-30 | 2024-12-31 | 2024-12-31 |
On this page