# RangeError: Invalid time value

**Code:** `invalid time value` · **Category:** JavaScript · **Seen on:** JavaScript

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

## 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.

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/javascript/rangeerror-invalid-time-value)
