Skip to content

Regex for Date (YYYY-MM-DD)

This regex matches dates in the ISO 8601 format YYYY-MM-DD. It validates that months are between 01-12 and days are between 01-31. The ISO 8601 date format is the international standard and is the recommended format for data interchange, APIs, and database storage. Note that this pattern does not validate logical date correctness (e.g., February 30).

Pattern
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$
Test this pattern in the Regex Tester →

What is the regex pattern for Date (YYYY-MM-DD)?

The regex pattern for Date (YYYY-MM-DD) is ^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$. This regex matches dates in the ISO 8601 format YYYY-MM-DD. It validates that months are between 01-12 and days are between 01-31. The ISO 8601 date format is the international standard and is the recommended format for data interchange, APIs, and database storage. Note that this pattern does not validate logical date correctness (e.g., February 30). This pattern is commonly used for api date validation and database date fields.

Test Examples

Match
2024-01-15
Matches: 2024-01-15
Match
2023-12-31
Matches: 2023-12-31
No Match
2024-13-01

Common Uses

Variations

With slashes

^\d{4}/(0[1-9]|1[0-2])/(0[1-9]|[12]\d|3[01])$

Uses forward slashes as separator

Flexible separator

^\d{4}[\-/](0[1-9]|1[0-2])[\-/](0[1-9]|[12]\d|3[01])$

Accepts dash or slash separators

Optional leading zeros

^\d{4}-(0?[1-9]|1[0-2])-(0?[1-9]|[12]\d|3[01])$

Allows single-digit months and days

Frequently Asked Questions

Does this validate dates like February 30?

No. This regex only checks the format. February 30, April 31, and other logically invalid dates will still match. You need programmatic validation to check calendar correctness.

Why use YYYY-MM-DD format?

ISO 8601 (YYYY-MM-DD) is the international standard for date representation. It sorts correctly as a string, is unambiguous across locales, and is the default format for most databases and APIs.

Can I use this for date range validation?

This regex only validates format, not ranges. To check if a date falls within a range, parse it into a Date object first, then compare programmatically.

Related Patterns

Date (MM/DD/YYYY)

^(0[1-9]|1[0-2])/(0[1-9]|[12]\d|3[01])/\...

ISO 8601 DateTime

^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[...

24-Hour Time

^([01]\d|2[0-3]):([0-5]\d)$

Related Reading

Regex Cheat Sheet with Examples for Developers → URL Encoding Special Characters →