invalid time value 🟨 JavaScript

RangeError: Invalid time value

A Date is invalid (NaN), and toISOString() or a formatting library couldn’t format it.

Seen on: JavaScript

Meaning

new Date(string) returns Invalid Date for unparseable strings; toISOString() then throws. Locale strings like "31/12/2024" aren’t parsed by Date.

Common causes

  • Unparseable date string
  • Undefined/null date
  • Non-ISO formats (DD/MM/YYYY)
  • date-fns/Intl given an invalid date

⚡ Quick fix

  1. Validate: isNaN(date.getTime())
  2. Use ISO 8601 strings (2024-12-31)
  3. Parse custom formats explicitly

Detailed fix by platform

JavaScript

  1. javascript
    const d = new Date(value);
    if (Number.isNaN(d.getTime())) throw new Error('Bad date: ' + value);

How to diagnose

  1. Input — What string/number produced the date?
  2. Recent change — Did it start after a deploy, upgrade, or configuration change? Compare with the last working version.

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.