DAYS_IN()
All functions > DATE AND TIME > DAYS_IN()
Returns the number of calendar days in the MONTH, QUARTER, HALF (half-year), or YEAR that contains the given date or timestamp.
Signatures
Returns: Inclusive day count for that calendar period
DAYS_IN(date: DATE | TIMESTAMP, unit: VARCHAR) → BIGINT sql
| Parameter | Type | Required | Description |
|---|---|---|---|
date | `DATE | TIMESTAMP` | Yes |
unit | VARCHAR | Yes | One of MONTH, QUARTER, HALF, YEAR (case-insensitive when provided as a literal) |
Notes
- Half uses January–June vs July–December (same boundaries as
FIRST_DAY_OF/LAST_DAY_OFwith unit HALF) - Quarter follows calendar quarters (same boundaries as
DATE_TRUNC(..., 'quarter')) - Year counts days in the calendar year containing
date(365 or 366) - Non-literal
unitvalues are evaluated at runtime; unknown values surface as an execution error - Returns NULL if
dateorunitis NULL
Examples
FeatureQL
SELECT
f1 := DAYS_IN(TIMESTAMP '2024-02-15 12:00:00', 'MONTH'), -- February in a leap year
f2 := DAYS_IN(TIMESTAMP '2023-02-15 12:00:00', 'MONTH'), -- February in a non-leap year
f3 := DAYS_IN(TIMESTAMP '2024-05-01 00:00:00', 'QUARTER'), -- Days in Q2 (Apr–Jun)
f4 := DAYS_IN(TIMESTAMP '2024-05-01 00:00:00', 'HALF'), -- First half of leap year 2024
f5 := DAYS_IN(TIMESTAMP '2024-09-01 00:00:00', 'HALF'), -- Second half of 2024
f6 := DAYS_IN(TIMESTAMP '2024-06-01 00:00:00', 'YEAR'), -- Leap calendar year
f7 := DAYS_IN(TIMESTAMP '2023-06-01 00:00:00', 'YEAR') -- Non-leap calendar year
;Result
| f1 BIGINT | f2 BIGINT | f3 BIGINT | f4 BIGINT | f5 BIGINT | f6 BIGINT | f7 BIGINT |
|---|---|---|---|---|---|---|
| 29 | 28 | 91 | 182 | 184 | 366 | 365 |
On this page