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
ParameterTypeRequiredDescription
date`DATETIMESTAMP`Yes
unitVARCHARYesPeriod name: WEEK, MONTH, QUARTER, HALF, or YEAR (case-insensitive when provided as a literal)

Notes

  • unit must 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 unit values are evaluated at runtime; unknown values surface as an execution error
  • Returns NULL if date or unit is 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 TIMESTAMPf2 TIMESTAMPf3 TIMESTAMPf4 TIMESTAMPf5 TIMESTAMPf6 TIMESTAMP
2024-03-312024-03-242024-03-312024-06-302024-12-312024-12-31

Last update at: 2026/05/26 17:22:09