LAST_DAY function in BigQuery
The LAST_DAY function in BigQuery returns the last day of a specified date period (such as a month, quarter, or year) based on a given DATE expression.
SQL Syntax
LAST_DAY(date_expression[, date_part])
We can optionally specify the date_part for which the last day is returned. If this parameter is not provided, the default value is MONTH.
Supported date_part Values
| date_part | Meaning |
|---|---|
| MONTH | Last day of the month (default) |
| QUARTER | Last day of the quarter |
| YEAR | Last day of the year |
Example: Last Day of the Month (Default Behavior)
SQL
SELECT LAST_DAY(DATE(2025, 06, 20), MONTH) AS last_day;
Output: 2025-06-30
Explanation
- June 2025 has 30 days.
- The function returns June 30, 2025.
Example: Last Day of the Year
SQL
SELECT LAST_DAY(DATE(2025, 06, 20), YEAR) AS last_day;
Output: 2025-12-31
Explanation
- The last day of the year 2025 is December 31.
Example: Last Day of the Quarter
SQL
SELECT LAST_DAY(DATE(2025, 06, 20), QUARTER) AS last_day;
Output: 2025-06-30
Explanation
- June falls in Q2.
- The last day of Q2 is June 30.