runtime
CRM + ERP Integration · milestone 04 / 12

milestone 4/12 Validate calendar dates before converting

Validate real calendar dates before converting text.

CRM + ERP Integration · Follow extraction reconciliation, authoritative integration, date quarantine, quality gates, stable keys, replay-safe loads, and atomic promotion. Finish with a customer-grain capstone and field-level lineage.

approach

Eight digits do not prove a valid date. Shape YYYYMMDD to YYYY-MM-DD, require exactly eight digits, and compare the candidate to SQLite date(candidate,+0 days) so normalization exposes impossible dates. Invalid or missing values remain NULL; keep the source row. SQL Server uses TRY_CONVERT with an explicit style.

worked-example.sql
WITH shaped AS(
  SELECT
    row_id,
    raw_date,
    SUBSTR(raw_date,1,4)||'-'||SUBSTR(raw_date,5,2)||'-'||SUBSTR(raw_date,7,2) AS candidate
  FROM raw_dates
)
SELECT
  row_id,
  raw_date,
  CASE
    WHEN raw_date GLOB '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
      AND date(candidate,'+0 days')=candidate
      THEN candidate
    ELSE NULL
  END AS clean_date
FROM shaped

data for this milestone

raw_dates2 columns · 8 rows
row_idinteger · keyraw_datetext
120250115
220250230
30
420240229
520251301

showing 5 of 8 rows

challenge 1

Return row_id,raw_date,clean_date for every raw_dates row.

Accept exactly eight digits and a valid calendar day; invalid values become NULL.

what to return

Columns
row_idraw_dateclean_date in this order
Rows
any order
challenge-1.sql
 
3 steps left · check both queries and pass the concept checkOpen the reportNext milestone
Validate calendar dates before converting — CRM + ERP Integration · Runtime