n8n-io/n8n · error · ExpressionExtensionError

Value is not a valid date

Error message

Value is not a valid date

What it means

The STRING `.toDateTime()` tries several parsers in turn — RFC2822, SQL, `DateTime.fromMillis(Date.parse(...))` — and if NONE yields a valid Luxon DateTime it throws 'Value is not a valid date'. This is the terminal failure after all auto-detection paths are exhausted.

Source

Thrown at packages/@n8n/expression-runtime/src/extensions/string-extensions.ts:84

	const httpDate = DateTime.fromHTTP(dateString, { zone: defaultZone, setZone: true });
	if (httpDate.isValid) {
		return httpDate;
	}
	const rfc2822Date = DateTime.fromRFC2822(dateString, { zone: defaultZone, setZone: true });
	if (rfc2822Date.isValid) {
		return rfc2822Date;
	}
	const sqlDate = DateTime.fromSQL(dateString, { zone: defaultZone, setZone: true });
	if (sqlDate.isValid) {
		return sqlDate;
	}

	const parsedDateTime = DateTime.fromMillis(Date.parse(dateString), { zone: defaultZone });
	if (parsedDateTime.isValid) {
		return parsedDateTime;
	}

	throw new ExpressionExtensionError('Value is not a valid date');
}

function hash(value: string, extraArgs: string[]): string {
	const algorithm = extraArgs[0]?.toLowerCase() ?? 'md5';
	switch (algorithm) {
		case 'base64':
			return toBase64(value);
		case 'md5':
			return MD5(value);
		case 'sha1':
		case 'sha224':
		case 'sha256':
		case 'sha384':
		case 'sha512':
		case 'sha3':
			const variant = (
				{
					sha1: 'SHA-1',

View on GitHub (pinned to 5ac6606e81)

Solutions

  1. Validate the string parses as a date before the expression runs (e.g. `!isNaN(Date.parse(x))`).
  2. If the format is known, pass it explicitly to a Luxon `fromFormat` call in a Code node.
  3. Provide a fallback with `.ifEmpty()` / conditional logic upstream so empty strings never reach `.toDateTime()`.

Example fix

// before
{{ $json.raw.toDateTime() }}
// after (guard in a Code node, then call the extension only when parseable)
Defensive patterns

Strategy: try-catch

Validate before calling

const s = $json.raw;
if (typeof s !== 'string' || !isNaN(Date.parse(s)) === false) {
  // route to a default branch instead of letting .toDateTime() throw
  $json.__dateValid = false;
} else {
  $json.__dateValid = true;
}
return $json;

Type guard

const isParsableDate = (s: string): boolean => !isNaN(Date.parse(s));

Try / catch

// Wrap expression evaluation (or use an Error Trigger / Set node fallback):
try {
  return $json.raw.toDateTime().toISO();
} catch {
  return null; // or route the item to a quarantine branch
}

Prevention

When it happens

Trigger: `.toDateTime()` on `'hello'`, `''`, `'2024-13-99'`, or any string none of the parsers accept.

Common situations: Empty field; wrong locale/format from an upstream system; free-text content in a field expected to hold a date.

Related errors


AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12). Data as JSON: /api/errors/7a66a54435912eb6. Report an issue: GitHub.