# API Error: Invalid date format — expected ISO 8601 (YYYY-MM-DDTHH:mm:ssZ)

**Code:** `invalid_date` · **Category:** API · **Seen on:** REST API

A date or timestamp in the request isn’t in the format the API expects — usually ISO 8601 with a time zone, or a Unix timestamp.

## Meaning

Dates are a classic source of 400/422 errors. Locale formats like 03/10/2026 are ambiguous, “2026-10-03 14:00” lacks the T separator and time zone, and some APIs want seconds since epoch while others want milliseconds or an RFC 3339 string.

Validators say things like “must match format "date-time"”, “Invalid datetime”, “Input should be a valid datetime” (Pydantic) or “Cannot deserialize value of type LocalDateTime” (Jackson).

## Common causes

- Locale-formatted string (dd/mm/yyyy, mm/dd/yyyy)
- Missing T separator or time zone/offset
- Milliseconds sent where the API expects seconds (or vice versa)
- Date object serialized in a non-standard way
- Invalid offset like +5:30 instead of +05:30

## Quick fix

1. Send ISO 8601/RFC 3339 strings in UTC: 2026-10-03T14:00:00Z
2. Use toISOString() / isoformat() instead of formatting by hand
3. Check whether the API wants seconds or milliseconds

## Detailed fix by platform

### Node.js

1. 

```javascript
const body = { start: new Date(start).toISOString() };          // 2026-10-03T14:00:00.000Z
const unix = Math.floor(Date.now() / 1000);                        // seconds, not ms
```


### Python

1. 

```python
from datetime import datetime, timezone
datetime.now(timezone.utc).isoformat()   # '2026-10-03T14:00:00+00:00'
```


## How to diagnose

1. **Raw value** — Exact string sent
2. **Docs** — ISO string, date-only, seconds or ms?
3. **Time zone** — Present and well-formed?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/api/invalid-date-format)
