IS_DATE

Return true if the input string can be parsed as a valid calendar date.

Category: miscReturns: BOOLEANDialect: PostgreSql

Syntax

IS_DATE(str)

Description

## Overview Returns TRUE if the input string can be parsed as a valid calendar date, FALSE otherwise, and NULL for a NULL input. Use this function to validate incoming date-like strings before casting to DATE, to quarantine badly formatted rows at ingest, or to build conditional transformations that tolerate mixed input formats. ## Validation rules - Primary format is ISO 8601: YYYY-MM-DD with a four-digit year, a two-digit month (01 through 12), and a two-digit day (01 through the last day of the month, accounting for leap years). - Also accepts common variations such as YYYY/MM/DD and YYYYMMDD. - Month and day are range-checked against the calendar, so 2025-02-30 returns FALSE and 2024-02-29 returns TRUE. - Leading and trailing whitespace is rejected; TRIM first if needed. - Does not accept timestamps (date + time) or relative strings such as 'today'. ## Behavior - Returns NULL for NULL input; otherwise always TRUE or FALSE. - Deterministic and side effect free. - No timezone processing is performed. ## Compatibility - Accepts the subset of date formats that the engine's DATE cast also accepts. If IS_DATE returns TRUE, `CAST(str AS DATE)` will succeed.

Parameters

NameTypeDescription
strSpecifies the string to test. ISO 8601 (YYYY-MM-DD) is the primary accepted form; common slash and dash-separated patterns are also recognized.

Examples

-- Valid ISO date
SELECT IS_DATE('2025-12-31');  -- true
-- Month out of range
SELECT IS_DATE('2025-13-01');  -- false
-- Non-date string
SELECT IS_DATE('hello');  -- false
-- Leap day valid only in leap years
SELECT IS_DATE('2024-02-29') AS leap_ok, IS_DATE('2023-02-29') AS not_leap;  -- true, false
-- Guard a cast to DATE
SELECT raw_dob,
       CASE WHEN IS_DATE(raw_dob) THEN CAST(raw_dob AS DATE) END AS dob
FROM crm.stage.raw_customers;
-- NULL propagation
SELECT IS_DATE(NULL);  -- NULL

Pitfalls

See Also

Open in interactive docs →   DeltaForge home →