{"record":{"id":"1c235614c76ce223","repo":"apache/cassandra","slug":"unable-to-parse-a-date-time-from-s","errorCode":null,"errorMessage":"Unable to parse a date/time from '%s'","messagePattern":"Unable to parse a date/time from '(.+?)'","errorType":"validation","errorClass":"MarshalException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/serializers/TimestampSerializer.java","lineNumber":177,"sourceCode":"            }\n            catch (NumberFormatException e)\n            {\n                throw new MarshalException(String.format(\"Unable to make long (for date) from: '%s'\", source), e);\n            }\n        }\n\n        for (DateTimeFormatter fmt: dateFormatters)\n        {\n            try\n            {\n                return ZonedDateTime.parse(source, fmt).toInstant().toEpochMilli();\n            }\n            catch (DateTimeParseException e)\n            {\n                continue;\n            }\n        }\n        throw new MarshalException(String.format(\"Unable to parse a date/time from '%s'\", source));\n    }\n\n    public static Format getJsonDateFormatter()\n    {\n    \treturn FORMATTER_TO_JSON.get();\n    }\n\n    public <V> void validate(V value, ValueAccessor<V> accessor) throws MarshalException\n    {\n        if (accessor.size(value) != 8 && !accessor.isEmpty(value))\n            throw new MarshalException(String.format(\"Expected 8 or 0 byte long for date (%d)\", accessor.size(value)));\n    }\n\n    public String toString(Date value)\n    {\n        return toStringUTC(value);\n    }\n","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/serializers/TimestampSerializer.java#L159-L195","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use an ISO-8601 format: '2015-05-03T13:30:54.234' or '2015-05-03 13:30:54.234+0000'","Add your format via -Dcassandra.timestamp_date_patterns=\"fmt1|fmt2\" so dateFormatters includes it","Pass epoch milliseconds as a plain long string instead","Pre-validate with one of the accepted formatters or OffsetDateTime.parse before insert"],"exampleFix":"// before\nsession.execute(\"INSERT INTO t (ts) VALUES (?)\", \"March 3, 2015\");\n// after\nsession.execute(\"INSERT INTO t (ts) VALUES (?)\", \"2015-03-03T00:00:00+0000\");","handlingStrategy":"validation","validationCode":"DateTimeFormatter FMT = DateTimeFormatter.ofPattern(\"yyyy-MM-dd HH:mm:ssZ\");\ntry { OffsetDateTime.parse(input, FMT); } catch (DateTimeParseException e) {\n  try { OffsetDateTime.parse(input); } catch (DateTimeParseException e2) { throw new IllegalArgumentException(\"unsupported timestamp format: \" + input); }\n}","typeGuard":"boolean isParsableTimestamp(String s) {\n  return TimestampSerializer.dateStringToTimestampQuiet(s); // wrap parse in try/catch returning boolean\n}","tryCatchPattern":"try {\n  session.execute(insert.bindString(\"ts\", input));\n} catch (InvalidQueryException e) {\n  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\");\n  throw e;\n}","preventionTips":["Standardize on ISO-8601 across all writers","If legacy formats are unavoidable, set -Dcassandra.timestamp_date_patterns with the needed patterns","Reject human-format dates ('March 3, 2015') at the API layer","Store and bind Instant objects via driver codecs when possible"],"tags":["cassandra","serialization","timestamp","invalid-date-format"],"backgroundTag":"invalid-date-format","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}