# Validate a Gregorian date

Check that a year, a 1-based month and a day form a real calendar date.

Canonical: https://1loc.dev/validator/validate-a-gregorian-date/
Version: 1.0.0
Runtime: JavaScript · Node.js 22 / modern browsers
Verification: Local fixtures; no external services
Updated: 2026-10-28

## Implementation

```javascript
function isValidDate({ year, month, day }) { const leap = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0); return day >= 1 && day <= [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month - 1]; }
```

## Input

```json
{
  "year": 2024,
  "month": 2,
  "day": 29
}
```

## Expected output

```json
true
```

## Edge case

Input:
```json
{
  "year": 2026,
  "month": 2,
  "day": 29
}
```
Output:
```json
false
```

## Limits

- The original used a zero-based month with new Date(y, m, 0), which reads the previous month’s length and accepted February 30. This version uses a 1-based month and explicit Gregorian rules.
- The lab accepts years 1–9,999 and months 1–12.

The lab validates types and size before calling this function. Add equivalent validation at your own trust boundary.

## Source and license

Original: https://github.com/phuocng/1loc/blob/14b481cf60dff1620ab1bb99a43b1f68068cdd9b/contents/validate-a-gregorian-date.mdx
Source file (this edition): https://github.com/akamind/1loc/blob/0a77f131b22d2ba3b7ec1728846f900c22821678/contents/validate-a-gregorian-date.mdx
Author: Nguyen Huu Phuoc and original contributors
Contributors: See original repository history
Source commit: 14b481cf60dff1620ab1bb99a43b1f68068cdd9b
Copyright (c) 2020 phuoc-ng
License: MIT — https://1loc.dev/licenses/
Maintainer: Oveyon
Modifications: Rewritten with a 1-based month and explicit Gregorian month lengths; the original zero-based month read the previous month's length and accepted February 30. Original MDX retained as inert source evidence.
