# JavaScript: “Invalid Date” / “RangeError: Invalid time value”

> new Date() shows Invalid Date, or toISOString throws RangeError: Invalid time value. Use ISO 8601 strings, check for undefined input, and validate with getTime.

Canonical: https://app369.com/fix/javascript-invalid-date/
Last updated: 2026-11-08

A date shows as Invalid Date on the page, a date library prints NaN, or toISOString() throws RangeError: Invalid time value. new Date() could not turn the input into a point in time. The usual input is a date string in a local format, an empty or undefined value, or a number in the wrong unit.

**Short answer**

Log the exact value passed to new Date(). Pass ISO 8601 strings (2026-12-31 or 2026-12-31T10:00:00Z), not local formats such as 31-12-2026 or 31/12/2026, which are invalid or parsed by browser-specific rules. Guard against undefined and empty values before creating the date. Check validity with Number.isNaN(date.getTime()) before calling toISOString() or formatting it. For other formats, parse the parts yourself or use a date library’s explicit format parser.

## **Why the date is invalid, and the fix**

1. 01 ### **A non-standard date string**
  > “This section contains implementation-specific behavior that may be inconsistent across browsers or different versions of browsers.” [**MDN, Date.parse(): non-standard date strings**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse) Only the ISO 8601 format is guaranteed to parse the same everywhere. Strings like 31-12-2026 give Invalid Date, 31/12/2026 is read with 31 as the month, and other formats such as 12/31/2026 follow implementation-specific rules that can differ by browser and version. Send and store ISO strings, and build dates from parts when you have to.```
new Date('2026-12-31T10:00:00Z'); // reliable

// from '31/12/2026'
const [d, m, y] = '31/12/2026'.split('/').map(Number);
const date = new Date(y, m - 1, d); // months start at 0
```
2. 02 ### **An empty, undefined or wrong value** new Date(undefined) and new Date('') are invalid, while new Date(null) quietly becomes January 1, 1970. A missing API field or form value is the usual source. Check the input first.```
function toDate(value) {
  if (value == null || value === '') return null;
  const date = new Date(value);
  return Number.isNaN(date.getTime()) ? null : date;
}
```
3. 03 ### **toISOString() on an invalid date**
  > “An invalid date is produced when you attempt to parse an invalid date string, or set the timestamp to an out-of-bounds value.” [**MDN, RangeError: invalid date**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_date) Most date methods return NaN for an invalid date, but toISOString() throws RangeError: Invalid time value. JSON.stringify does not throw: it writes null for an invalid date, which can quietly corrupt saved data. Validate before you serialize.
4. 04 ### **Seconds instead of milliseconds** new Date() takes milliseconds. A Unix timestamp in seconds (from many APIs and databases) gives a date in January 1970 instead of an error. Multiply by 1000.```
const date = new Date(createdAtSeconds * 1000);
```

Checked against the vendor’s docs on November 8, 2026: [MDN: RangeError: invalid date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_date); [MDN: Date.parse()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse).

## **Rather hand it over?**

Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.

- [from $450**App Fix Ticket**One reproducible bug in an existing mobile or web app, diagnosed and fixed.**See scope and start**](https://app369.com/fixed-price/flutter-firebase-bug-fix/)
- [from $450**AI-Built App Rescue**A Lovable, Bolt or Cursor app checked end to end in 3 days, then its worst problems fixed at a fixed price.****No issues worth fixing, no charge.**** If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.**See scope and start**](https://app369.com/fixed-price/ai-app-rescue/)

Related: [**“Cannot read properties of undefined”**](https://app369.com/fix/cannot-read-properties-of-undefined/) · [**“Unexpected end of JSON input”**](https://app369.com/fix/unexpected-end-of-json-input/) · [**TypeError: “x is not a constructor”**](https://app369.com/fix/is-not-a-constructor/)

Questions

## **More on this error**

<details>

<summary>**Why does it work in Chrome but show Invalid Date in Safari? **+</summary>

The string is not in the ISO format, so each browser can use its own parsing rules, and they do not always agree. Change the data to ISO 8601, or parse the parts yourself.

</details>

<details>

<summary>**Why is my date one day off? **+</summary>

A date-only ISO string such as 2026-12-31 is read as midnight UTC, which is the previous day in time zones west of UTC. Use new Date(2026, 11, 31) for a local date, or keep dates as strings until display.

</details>

<details>

<summary>**Can you fix it for me? **+</summary>

If one bug is the whole problem, the App Fix Ticket covers it: a written diagnosis first, then the fix. If the app has more going on, the Launch Check is a written check of the whole app. Each issue found is rated critical, high, medium or low, with where it is and how it was confirmed. No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.

</details>

A different error?

## **Describe it and get a written quote**

Send the error and what you were doing. You get a written scope, a fixed price and a timeline; Simon replies by email, usually within one business day.

[**Describe your problem **→](https://app369.com/contact/) [**All fixes**](https://app369.com/fix/)