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
ParameterTypeRequiredDescription
date`DATETIMESTAMP`Yes
unitVARCHARYesOne 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_OF with 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 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 := 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 BIGINTf2 BIGINTf3 BIGINTf4 BIGINTf5 BIGINTf6 BIGINTf7 BIGINT
292891182184366365

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