SQL Server Error 210 (Conversion Failed) occurs when you try to insert, update, or convert a datetime value that isn’t in the correct format—often because the binary data (like a raw timestamp or hex string) doesn’t match SQL Server’s expected structure. This is a common issue when migrating data, restoring from backups, or manually entering complex datetime expressions. The error means the system can’t convert the binary/string/text input into a valid datetime format (YYYY-MM-DD HH:MM:SS or similar). Below is how to diagnose and fix it.

What You'll Need

  • A SQL Server client tool (SSMS, Query Editor, T-SQL editor) or direct access to the database
  • The table, column, and exact query/insert statement triggering the error
  • Basic knowledge of SQL syntax (though the steps are concrete)

Step-by-Step Resolution

  1. Identify the problematic data: Run this query to examine the exact binary/string value causing the issue: SELECT CAST(raw_data AS VARBINARY(MAX)) AS RawValue, CONVERT(VARCHAR(MAX), raw_data, 1) AS HexValue FROM your_table WHERE column_name = 'your_value_here'; This reveals whether the value is in binary format (hex/bytes) or plain text. Note the hex representation if you see raw bytes.
  2. Convert to a valid datetime format: Use one of these methods based on the data type of the column:
    • If the column is DATETIME/DATETIME2, cast with: CONVERT(DATETIME, 'YYYY-MM-DD HH:MM:SS', 120) AS datetime_column (where 120 specifies the ISO format)
    • For binary timestamps (e.g., '1234567890'), create a helper function: CREATE FUNCTION dbo.BinaryToDate(@BinaryData VARBINARY(8)) RETURNS DATETIME BEGIN RETURN CONVERT(DATETIME, CONVERT(VARCHAR(10), @BinaryData, 2)); END; Then use it in INSERT/UPDATE.
    • If the data is a string like '2023-11-15 14:30:00', use: CONVERT(DATETIME, '2023-11-15 14:30:00', 120) AS valid_datetime
  3. Update the table in batches: Use a transaction to handle errors gracefully: BEGIN TRY BEGIN TRANSACTION; UPDATE your_table SET datetime_column = CONVERT(DATETIME, 'YYYY-MM-DD HH:MM:SS', 120) WHERE column_matches_pattern = 'invalid_value'; COMMIT TRANSACTION; END TRY BEGIN CATCH IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION; PRINT 'Error: ' + ERROR_MESSAGE(); END CATCH;
  4. Create a fallback value: If the conversion fails completely, replace with a default date: UPDATE your_table SET datetime_column = CASE WHEN CONVERT(DATETIME, '0001-01-01', 120) = '0001-01-01 00:00:00' THEN CONVERT(DATETIME, '1900-01-01 00:00:00', 120) ELSE CONVERT(DATETIME, '0001-01-01', 120) -- Minimal valid value END;
  5. Validate the column type: Check if the column can actually store datetime values: SELECT COLUMN_PROPERTY(your_column_name, 'IS_NULLABLE') AS Nullable, COLUMN_PROPERTY(your_column_name, 'DATA_TYPE') AS DataType, COLUMN_PROPERTY(your_column_name, 'MAX_LENGTH') AS MaxLength FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'your_table'; If it’s VARCHAR/NVARCHAR, convert to DATETIME properly. If it’s BINARY, use the binary-to-date function above.

If That Did Not Work

If the error persists after these steps, the issue lies elsewhere:
  • The binary data is corrupted or invalid beyond repair—you’ll need to rebuild the record or exclude it from updates.
  • The datetime column is configured to allow only specific formats (e.g., UTC instead of local time)—check the column properties (right-click column > Properties > Collation in SSMS).
  • You’re trying to insert a NULL value when the column is set to NOT NULL—add a default value or modify the schema first.

Common Mistakes

  • Using incorrect format codes: SQL Server format codes (e.g., 120 for ISO) must match the column’s expected format. A hex string formatted as '1234567890' won’t convert with 120.
  • Treat binary timestamps as strings: Converting a binary value (like a 4-byte timestamp) directly to a string with CONVERT(VARCHAR) fails—use hex conversion (1) or a binary-to-date function.
  • Overlooking timezone issues: If the column uses a collation like 'SQL_Latin1_General_CP1_CI_AS', ensure your data matches that timezone (e.g., '2023-11-15 14:30:00 +00:00').
  • Ignoring NULL handling: Inserting a NULL into a datetime column that isn’t NULL-allowed will trigger this error. Use COALESCE to replace NULLs with a default date first.
  • Tips

    • Prevent future errors: Standardize datetime formats in your application code to avoid inconsistencies. Use ISO 8601 (YYYY-MM-DDTHH:MM:SS) for cross-platform compatibility.
    • Test with a small subset: Run the update query on a sample row first to verify the conversion logic works before applying it to the entire table.
    • Use TRY-CATCH for scripts: In production, wrap datetime conversions in TRY-CATCH blocks to handle errors gracefully and log problematic rows.
    • Check for legacy data: If you’re importing historical data, verify the original source’s datetime format (e.g., Excel might store dates as serial numbers).
    • Consider column type changes: If the issue recurs, reconsider the column type—DATETIME2 (10-digits precision) is better than DATETIME (7-digits) for high-precision timestamps.

    Troubleshooting

    1. Error persists with 'conversion failed' but no specific format: Check the exact binary value using: SELECT CONVERT(VARCHAR(MAX), raw_data, 1) AS HexDump FROM your_table WHERE column_name = 'your_value'; If you see '0x' or hex digits, the data is binary—use a binary-to-date function.
    2. Multiple rows fail consistently: Add a WHERE clause to target problematic rows: UPDATE your_table SET datetime_column = CASE WHEN RIGHT(raw_data, 2) = '00' THEN CONVERT(DATETIME, '1900-01-01', 120) ELSE CONVERT(DATETIME, '2000-01-01', 120) END WHERE binary_column = '0x12345678'; -- Your specific hex pattern
    3. Using SSIS/ETL tools: In SSIS, set the "Data Conversion" property to 'Convert to Default Type' for datetime columns. If the error still occurs, map the source field to a datetime type in the Data Flow task.
    4. Restoring from a backup: Use RESTORE WITH REPLACE (for new tables) or REPLACE for existing tables. If the error occurs during restore, check the backup file’s datetime metadata (e.g., '20230101' might need conversion).

    Frequently Asked Questions

    Why does SQL Server reject my datetime binary data?

    SQL Server expects datetime values to be in a standard format (YYYY-MM-DD HH:MM:SS) or a collation-specific format. Binary data like hex strings or raw timestamps (e.g., 4-byte integer timestamps) aren’t natively compatible; they must be converted to text or a specialized function to work.

    How do I convert a Unix timestamp (seconds since 1970) in binary to a datetime?

    Use this function: CREATE FUNCTION dbo.UnixToDate(@Seconds INT) RETURNS DATETIME BEGIN RETURN DATEADD(DAY, @Seconds, '1970-01-01'); END; Then insert with: UPDATE your_table SET datetime_column = dbo.UnixToDate(1700000000); -- Example timestamp

    What can I do if the column is VARCHAR and I can’t change its type?

    Use a computed column with a TRY-CATCH block to handle invalid values: CREATE TABLE your_table ( id INT IDENTITY, invalid_datetime VARCHAR(20) NULL, parsed_datetime DATETIME AS (TRY_CONVERT(DATETIME, invalid_datetime, 120)), CONSTRAINT DF_parsed_datetime DEFAULT (TRY_CONVERT(DATETIME, '1900-01-01', 120)) ); This will convert valid dates silently and return NULL for invalid entries.

    Why does my SSMS query say "conversion failed" but works in another tool?

    The issue often stems from:

    • Different format codes in SSMS vs. other tools (e.g., SSMS defaults to 120 for ISO, but your tool uses a different code).
    • Collation differences—SQL Server may enforce stricter datetime validation than some ETL tools.
    • The source data has trailing whitespace or inconsistent formats that SSMS detects but your tool doesn’t.
    Check the query’s actual format code and collation in SSMS (right-click column > Properties > Collation).

    How can I find all rows with invalid datetime data in my table?

    Run this query to identify problematic rows: SELECT * FROM your_table WHERE -- For VARCHAR columns: TRY_CONVERT(DATETIME, column_name, 120) IS NULL OR -- For BINARY columns: CONVERT(VARCHAR(MAX), column_name, 1) = '0x' -- Indicates binary data OR -- For specific patterns (e.g., non-Iso8601 formats): REGEXP_LIKE(column_name, '[^0-9A-Fa-f\\-: ]+'); Adjust the conditions based on your data type and expected format.

    What should I do if my datetime column is corrupted beyond repair?

    You have two options:

    • Backup and rebuild: Create a new table with the same structure, restore a clean backup, and populate the datetime data manually. This is safest if the corruption is rare.
    • Use a temporary column: Add a new datetime column during maintenance windows, copy valid data from other sources, and then replace the problematic column with the new one.

    Why does the same datetime string fail in one query but work in another?

    This typically happens due to:

    • Case sensitivity: SQL Server treats '2023-11-15' and '2023-11-15' (lowercase 'L') differently in some collations. Use CONVERT with UPPER() or ensure consistent casing.
    • Timezone offsets: If the column uses a collation like 'SQL_Latin1_General_CP1_CI_AS', the string '2023-11-15 14:30:00 +00:00' must match the collation’s timezone settings exactly.
    • Hidden characters: The string might contain non-printable characters (e.g., BOM markers in UTF-8) that SQL Server ignores by default but your tool doesn’t. Use SELECT [CHARACTER_SET_CLEANER](column_name) to clean them.

    For persistent issues, inspect the exact query execution plan in SSMS (right-click query > Graph Execution Plan) to see if the optimizer is skipping validation steps.