FIRST_DAY_OF()
All functions > DATE AND TIME > FIRST_DAY_OF()
Returns the first calendar day of the period containing the given date or timestamp, as midnight on that day.
Signatures
Returns: Midnight TIMESTAMP on the first day of the period
FIRST_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 (first day is January 1 or July 1)
- Non-literal
unitvalues are evaluated at runtime; unknown values surface as an execution error - Returns NULL if
dateorunitis NULL
Examples
FeatureQL
SELECT
f1 := FIRST_DAY_OF(TIMESTAMP '2024-03-20 15:00:00', 'MONTH'), -- Start of March
f2 := FIRST_DAY_OF(TIMESTAMP '2024-03-20 12:00:00', 'WEEK'), -- ISO week containing 20 Mar 2024 starts Monday
f3 := FIRST_DAY_OF(TIMESTAMP '2024-02-10 00:00:00', 'QUARTER'), -- Start of Q1
f4 := FIRST_DAY_OF(TIMESTAMP '2024-05-01 00:00:00', 'HALF'), -- Start of first half-year
f5 := FIRST_DAY_OF(TIMESTAMP '2024-09-01 00:00:00', 'HALF'), -- Start of second half-year
f6 := FIRST_DAY_OF(TIMESTAMP '2024-07-04 00:00:00', 'YEAR') -- Start of calendar year
;Result
| f1 TIMESTAMP | f2 TIMESTAMP | f3 TIMESTAMP | f4 TIMESTAMP | f5 TIMESTAMP | f6 TIMESTAMP |
|---|---|---|---|---|---|
| 2024-03-01 | 2024-03-18 | 2024-01-01 | 2024-01-01 | 2024-07-01 | 2024-01-01 |
On this page