BigQuery · Date function
BigQuery LAST_DAY
LAST_DAY(date) returns the last day of the month that contains a date, such as 2026-11-30 for 2026-11-23. Pass QUARTER, YEAR, WEEK, ISOWEEK or ISOYEAR as a second argument for the last day of other periods.
LAST_DAY returns the final DATE of the period that contains the input. Without a second argument the period is MONTH, which covers the common question "what is the end of this month". Leap years are handled: LAST_DAY(DATE '2028-02-10') is February 29.
Other periods: QUARTER and YEAR return the quarter and year end. WEEK weeks start on Sunday, so the last day is a Saturday; WEEK(MONDAY) and ISOWEEK end on Sunday. ISOYEAR returns the Sunday before the next ISO year starts, which can fall in early January.
LAST_DAY also accepts a DATETIME and still returns a DATE. Pair it with DATE_TRUNC for the first day of the same period.
Syntax
LAST_DAY(date_expression[, date_part])Arguments and return value
| Argument | Description |
|---|---|
date_expression | A DATE (or DATETIME). NULL returns NULL. |
date_part | Optional, unquoted: MONTH (default), QUARTER, YEAR, WEEK, WEEK(<WEEKDAY>), ISOWEEK or ISOYEAR. |
Returns: DATE
Examples
End of the month, quarter and year
SELECT
LAST_DAY(DATE '2026-11-23') AS month_end,
LAST_DAY(DATE '2026-11-23', QUARTER) AS quarter_end,
LAST_DAY(DATE '2026-11-23', YEAR) AS year_end,
LAST_DAY(DATE '2028-02-10') AS leap_february_end;| month_end | quarter_end | year_end | leap_february_end |
|---|---|---|---|
| 2026-11-30 | 2026-12-31 | 2026-12-31 | 2028-02-29 |
End of the week and the ISO year
ISO year 2027 starts on Monday, January 4, 2027, so ISO year 2026 ends on Sunday, January 3.
SELECT
LAST_DAY(DATE '2026-11-23', WEEK) AS sunday_week_end,
LAST_DAY(DATE '2026-11-23', WEEK(MONDAY)) AS monday_week_end,
LAST_DAY(DATE '2026-11-23', ISOWEEK) AS iso_week_end,
LAST_DAY(DATE '2026-11-23', ISOYEAR) AS iso_year_end;| sunday_week_end | monday_week_end | iso_week_end | iso_year_end |
|---|---|---|---|
| 2026-11-28 | 2026-11-29 | 2026-11-29 | 2027-01-03 |
Days left in the month and a month-end flag
WITH payments AS (
SELECT 'p1' AS payment_id, DATE '2026-11-23' AS paid_on UNION ALL
SELECT 'p2', DATE '2026-11-30' UNION ALL
SELECT 'p3', DATE '2026-02-28'
)
SELECT
payment_id,
DATE_DIFF(LAST_DAY(paid_on), paid_on, DAY) AS days_left_in_month,
paid_on = LAST_DAY(paid_on) AS is_month_end
FROM payments
ORDER BY payment_id;| payment_id | days_left_in_month | is_month_end |
|---|---|---|
| p1 | 7 | false |
| p2 | 0 | true |
| p3 | 0 | true |
DATETIME input returns a DATE
SELECT LAST_DAY(DATETIME '2026-11-23 18:45:00') AS month_end;| month_end |
|---|
| 2026-11-30 |
Common mistakes
- Computing month ends by hand.
DATE_SUB(DATE_ADD(DATE_TRUNC(d, MONTH), INTERVAL 1 MONTH), INTERVAL 1 DAY)works but is easy to get wrong;LAST_DAY(d)is the same thing. - Expecting
LAST_DAY(d, WEEK)to be a Sunday.WEEKstarts on Sunday, so it ends on Saturday. UseWEEK(MONDAY)orISOWEEKfor Sunday week ends. - Using a month end as an exclusive upper bound on a TIMESTAMP or DATETIME column.
ts <= LAST_DAY(d)stops at midnight on the last day and misses that whole day; usets < DATE_ADD(LAST_DAY(d), INTERVAL 1 DAY)or the first day of the next month. - Porting
EOMONTH(d)from SQL Server or Excel, or Snowflake'sLAST_DAY(d, 'month')with a quoted part. In BigQuery the part is an unquoted keyword.
FAQ
How do I get the last day of the month in BigQuery?
LAST_DAY(d) or LAST_DAY(d, MONTH). For the current month: LAST_DAY(CURRENT_DATE()).
How do I get the last day of the previous month?
LAST_DAY(DATE_SUB(d, INTERVAL 1 MONTH)), or DATE_TRUNC(d, MONTH) - 1.
Does LAST_DAY handle leap years?
Yes. LAST_DAY(DATE '2028-02-10') returns 2028-02-29 and LAST_DAY(DATE '2026-02-10') returns 2026-02-28.
Related
More date functions
All BigQuery date functions · All functions · BigQuery error messages
