# Conversion Error: The date or timestamp string is malformed

> A string cast to DATE, TIME or TIMESTAMP did not match the format DuckDB expects.

Source: https://sqlly.app/errors/duckdb/conversion-invalid-date
Last updated: 2026-11-30
License: Text and data [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) (credit SQLly, sqlly.app); code and SQL snippets [MIT](https://opensource.org/license/mit). [Details](https://sqlly.app/license).
Note: Quoted error message text belongs to its database vendor.

- Exception: `Conversion Error`
- Category: Conversion and range errors

Error message:

```text
Conversion Error: invalid date field format: "not a date", expected format is (YYYY-MM-DD)
```

## What it means

Casting text to a temporal type uses DuckDB's own expected layout: `YYYY-MM-DD` for dates and the ISO layout for timestamps. When a value does not fit, the error quotes the offending string and the expected format, and the whole statement stops on the first bad value.

A plain cast takes no format argument and is all-or-nothing. Text in another layout, such as `25/12/2024`, is not read as a date at all: parse it with `strptime`, which takes an explicit format string, or with `try_strptime`, which returns NULL for values that do not match instead of failing.

## Common causes

- A CSV column inferred as DATE or TIMESTAMP while some rows hold text in another layout.
- Day-first or month-first strings such as 25/12/2024, which no plain cast accepts.
- Locale month names such as Dec 25 2024, which no plain cast accepts.
- An empty string cast to DATE, which fails instead of becoming NULL.

## How to fix it

1. See how many values will not parse before changing the load:

   ```sql
   SELECT count(*) FROM stage
   WHERE raw_date IS NOT NULL AND TRY_CAST(raw_date AS DATE) IS NULL;
   ```
2. Parse a known nonstandard layout with strptime:

   ```sql
   SELECT strptime(raw_date, '%d/%m/%Y')::DATE FROM stage;
   ```
3. Read the file as text first and parse deliberately. This assumes every row uses the same layout. For a mixed column, use the try_strptime step below instead:

   ```sql
   CREATE TABLE stage AS
   SELECT * FROM read_csv('input.csv', all_varchar = true);
   SELECT strptime(raw_date, '%d/%m/%Y')::DATE FROM stage;
   ```
4. For values that may be dirty, use try_strptime and inspect what came back NULL:

   ```sql
   SELECT raw_date FROM stage
   WHERE try_strptime(raw_date, '%d/%m/%Y') IS NULL AND raw_date IS NOT NULL;
   ```

## Reproduce it safely

```sql
SELECT 'not a date'::DATE;   -- Conversion Error: invalid date field format: "not a date", expected format is (YYYY-MM-DD)
```

## Questions

### What format does DuckDB expect for dates?

ISO: YYYY-MM-DD for DATE and YYYY-MM-DD HH:MM:SS for TIMESTAMP. Anything else needs strptime with an explicit format.

### How do I handle a column with mixed date formats?

Normalize in staging: read as VARCHAR, try each format with coalesce(try_strptime(x, f1), try_strptime(x, f2)), and route what is left to a rejects list.

## Related errors

- [`Conversion Error`](https://sqlly.app/errors/duckdb/conversion-could-not-convert): The value cannot be cast to the target type
- [`Conversion Error`](https://sqlly.app/errors/duckdb/conversion-out-of-range): The value is out of range for INT32
- [`22007`](https://sqlly.app/errors/postgresql/22007): PostgreSQL: invalid datetime format

The code and message text are from the [DuckDB documentation](https://duckdb.org/docs/).
