elefcode

Regex pattern

Date Regex (ISO 8601) — free online tester

Match ISO 8601 dates (YYYY-MM-DD) and optionally times in any text — the format JSON APIs, databases, and logs use.

The pattern

/\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:?\d{2})?)?/g

How it works

ISO 8601 is the de-facto standard for dates in machine-readable formats: 2024-05-20. This regex matches the date portion and (optionally) an "T HH:MM:SS" time with an optional "Z" or numeric timezone offset, so it handles both bare dates and full timestamps emitted by APIs.

When to use it

  • Extract dates from JSON / API logs
  • Find timestamps in log files
  • Validate date form fields before parsing
  • Migrate datestamps in scraped data

Tip

This pattern matches the shape but doesn't validate that the month is 1–12 or that February has fewer than 30 days. Use new Date() to validate after extraction.

Try it on this input

Event date: 2024-05-20
Created: 2024-05-20T14:30:00Z
Updated: 2024-05-20T14:30:00.123-05:00
Birthday: 1990-01-15
Yesterday: 2024-03-08
Not dates: 24-05-20, 2024/05/20, May 20 2024, 99-99-99

What this pattern doesn't catch

  • Matches malformed dates like 2024-99-99 (month 99 doesn't exist)
  • Doesn't catch other date formats (DD/MM/YYYY, Month Day, Year, etc.)
  • For strict validation, use a date parser after the match

More regex patterns