apache/cassandra · error · MarshalException

Unable to parse a date/time from '%s'

Error message

Unable to parse a date/time from '%s'

What it means

TimestampSerializer tries a list of configured DateTimeFormatters (default and system-property-configured formats, e.g. ISO and 'yyyy-MM-dd HH:mm:ssZ' variants) and throws this MarshalException when none of them can parse the string. It means the value is neither a valid long nor matches any supported date/time string format.

Source

Thrown at src/java/org/apache/cassandra/serializers/TimestampSerializer.java:177

            }
            catch (NumberFormatException e)
            {
                throw new MarshalException(String.format("Unable to make long (for date) from: '%s'", source), e);
            }
        }

        for (DateTimeFormatter fmt: dateFormatters)
        {
            try
            {
                return ZonedDateTime.parse(source, fmt).toInstant().toEpochMilli();
            }
            catch (DateTimeParseException e)
            {
                continue;
            }
        }
        throw new MarshalException(String.format("Unable to parse a date/time from '%s'", source));
    }

    public static Format getJsonDateFormatter()
    {
    	return FORMATTER_TO_JSON.get();
    }

    public <V> void validate(V value, ValueAccessor<V> accessor) throws MarshalException
    {
        if (accessor.size(value) != 8 && !accessor.isEmpty(value))
            throw new MarshalException(String.format("Expected 8 or 0 byte long for date (%d)", accessor.size(value)));
    }

    public String toString(Date value)
    {
        return toStringUTC(value);
    }

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Use an ISO-8601 format: '2015-05-03T13:30:54.234' or '2015-05-03 13:30:54.234+0000'
  2. Add your format via -Dcassandra.timestamp_date_patterns="fmt1|fmt2" so dateFormatters includes it
  3. Pass epoch milliseconds as a plain long string instead
  4. Pre-validate with one of the accepted formatters or OffsetDateTime.parse before insert

Example fix

// before
session.execute("INSERT INTO t (ts) VALUES (?)", "March 3, 2015");
// after
session.execute("INSERT INTO t (ts) VALUES (?)", "2015-03-03T00:00:00+0000");
Defensive patterns

Strategy: validation

Validate before calling

DateTimeFormatter FMT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ssZ");
try { OffsetDateTime.parse(input, FMT); } catch (DateTimeParseException e) {
  try { OffsetDateTime.parse(input); } catch (DateTimeParseException e2) { throw new IllegalArgumentException("unsupported timestamp format: " + input); }
}

Type guard

boolean isParsableTimestamp(String s) {
  return TimestampSerializer.dateStringToTimestampQuiet(s); // wrap parse in try/catch returning boolean
}

Try / catch

try {
  session.execute(insert.bindString("ts", input));
} catch (InvalidQueryException e) {
  if (e.getMessage().contains("Unable to parse a date/time")) throw new BadRequestException("use ISO-8601, e.g. 2015-05-03T13:30:54.234+0000");
  throw e;
}

Prevention

When it happens

Trigger: Inserting strings like 'March 3, 2015', '03/03/2015', RFC-1123 strings, or a format not in cassandra.timestamp_date_patterns / not ISO-8601 into a timestamp column; timezone-less ambiguous formats.

Common situations: Data exported from other databases in their default string formats; missing -Dcassandra.timestamp_date_patterns configuration for custom formats; JavaScript Date.toString() output pasted into CQL.

Understand the failure class

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/1c235614c76ce223. Report an issue: GitHub.