To fix SQL Server’s “Conversion failed when converting date and/or time from character string” error, find the string value or literal being implicitly or explicitly cast to DATE, DATETIME, DATETIME2, SMALLDATETIME, or DATETIMEOFFSET that does not match a valid date/time format—and switch to an unambiguous format (YYYY-MM-DD for DATE/DATETIME2 or YYYYMMDD for DATETIME/SMALLDATETIME) or filter/validate bad strings safely with TRY_CAST() / TRY_CONVERT().
- Identify Which Value or Expression Is Failing The error occurs at runtime whenever SQL Server tries to convert a string (VARCHAR, NVARCHAR, CHAR, NCHAR) into a date/time type and encounters:
An invalid calendar date (such as ‘2026-02-29’ in a non-leap year or ‘2026-13-01’).
Empty strings (‘’) or whitespace/garbage text (‘N/A’, ‘TBD’).
Regional ambiguity (such as ‘13/05/2026’ when MM/DD/YYYY is expected, or ‘05/13/2026’ under a DD/MM/YYYY language/dateformat setting).
A predicate filter or CASE expression where SQL Server evaluates conversion on rows you thought were filtered out.
- Isolate Bad Rows with TRY_CONVERT() or TRY_CAST() If a VARCHAR/NVARCHAR column holds mixed text or invalid dates, run a diagnostic query using TRY_CONVERT() (which returns NULL instead of aborting the batch on invalid strings):
SQL – Find rows where raw_date_text cannot convert to DATETIME2 SELECT id, raw_date_text FROM dbo.imported_records WHERE raw_date_text IS NOT NULL AND LTRIM(RTRIM(raw_date_text)) <> ‘’ AND TRY_CONVERT(DATETIME2, raw_date_text) IS NULL; If TRY_CONVERT() itself throws an error, the target data type is incompatible with the source type (for example, passing an invalid style code).
If TRY_CONVERT() returns NULL for specific rows, inspect raw_date_text on those rows to see the exact offending format.
- Use Unambiguous Date Formats and Explicit Styles Always Use Unambiguous Literals in Queries Use YYYY-MM-DD (or ISO 8601 ‘YYYY-MM-DDTHH:MM:SS’) for DATE and DATETIME2—it is language- and session-independent.
Use YYYYMMDD (no hyphens) when comparing or inserting into DATETIME or SMALLDATETIME across varying regional/language settings.
SQL – Safe for DATE and DATETIME2 across session settings SELECT order_id, created_at FROM dbo.orders WHERE created_at >= ‘2026-11-30T00:00:00’; Specify a Format Style When Parsing Non-ISO Strings When input strings come in a known non-ISO format (for example, ‘30/11/2026’ = British/French dd/mm/yyyy style 103), pass the explicit style code to CONVERT() / TRY_CONVERT():
SQL SELECT raw_date_text, TRY_CONVERT(DATE, raw_date_text, 103) AS parsed_date FROM dbo.staging_dates WHERE TRY_CONVERT(DATE, raw_date_text, 103) IS NULL AND raw_date_text IS NOT NULL; 4. Watch Out for CASE Evaluation Order and Implicit Casts SQL Server can evaluate THEN / ELSE expressions or WHERE predicates in an order that triggers conversion errors even on rows you expect to skip:
SQL – Risky: SQL Server may evaluate CONVERT on all rows before outer filtering SELECT CASE WHEN ISDATE(raw_date_text) = 1 THEN CONVERT(DATE, raw_date_text) ELSE NULL END AS safe_date FROM dbo.staging_dates;
– Safer: TRY_CONVERT avoids throwing on non-convertible strings directly SELECT TRY_CONVERT(DATE, raw_date_text) AS safe_date FROM dbo.staging_dates; Note that ISDATE() returns 1 for some strings that fail when converted to DATETIME2 or DATE (such as certain time-only strings or DATETIME range edge cases), so TRY_CONVERT() / TRY_CAST() is generally more reliable than ISDATE().
- Prevention Checklist for Production T-SQL Store dates in DATE, DATETIME2, or DATETIMEOFFSET columns—never in VARCHAR or NVARCHAR columns.
Use YYYY-MM-DD / YYYY-MM-DDTHH:MM:SS (or YYYYMMDD for DATETIME) for string literals rather than slash-delimited dates (MM/DD/YYYY or DD/MM/YYYY).
Clean and validate incoming strings at ingestion using TRY_CONVERT() / TRY_CAST() and log or quarantine invalid values rather than letting a single bad row fail a batch.
Check JOIN and WHERE data types so a string column is not implicitly converted against a date column (or vice versa) in an unexpected way.
