HTML Guides for datetime
Learn how to identify and fix common HTML validation errors flagged by the W3C Validator — so your pages are standards-compliant and render correctly across every browser. Also check our Accessibility Guides.
type="datetime" is obsolete; it was removed from HTML and is not valid in modern browsers or validators.
Explanation
The input element’s type attribute accepts specific keywords defined by the HTML Living Standard. The keyword datetime was dropped; use either:
- type="datetime-local" for a local date and time without timezone.
- type="date" or type="time" when collecting them separately.
- type="text" with a pattern or a JS widget when timezone-aware datetime is required.
Relevant attributes that still apply include name, value, min, max, and step (e.g., seconds for datetime-local).
HTML examples
Example reproducing the error
<!DOCTYPE html>
<html lang="en">
<head>
<title>Invalid input type</title>
</head>
<body>
<form>
<label>
Meeting:
<input type="datetime" name="meeting">
</label>
</form>
</body>
</html>
Valid fix with datetime-local
<!DOCTYPE html>
<html lang="en">
<head>
<title>Valid input type</title>
</head>
<body>
<form>
<label>
Meeting:
<input type="datetime-local" name="meeting" step="60">
</label>
</form>
</body>
</html>
The <time> HTML element represents a specific period in time or a duration. Its datetime attribute translates human-readable text into a machine-readable format, enabling browsers, search engines, and assistive technologies to reliably parse and understand temporal data. When the datetime value doesn’t match one of the accepted formats, the machine-readable purpose of the element is defeated — tools cannot interpret the date or time, which undermines features like search engine rich results, calendar integration, and accessibility enhancements for screen readers.
The HTML specification defines several valid formats for the datetime attribute. Here are the most commonly used ones:
| Format | Example | Description |
|---|---|---|
| Date | 2024-03-15 | Year, month, day |
| Month | 2024-03 | Year and month only |
| Year | 2024 | Valid year |
| Yearless date | 03-15 | Month and day without year |
| Time | 14:30 or 14:30:00 | Hours and minutes (seconds optional) |
| Date and time | 2024-03-15T14:30 | Date and time separated by T |
| Date and time with timezone | 2024-03-15T14:30Z or 2024-03-15T14:30+05:30 | With UTC (Z) or offset |
| Duration (precise) | PT1H30M | ISO 8601 duration |
| Duration (approximate) | P2Y6M | Years, months, etc. |
| Week | 2024-W12 | ISO week number |
Common mistakes that trigger this error include:
- Using slashes instead of hyphens: 03/15/2024 instead of 2024-03-15
- Using informal date formats: March 15, 2024 or 15-03-2024
- Omitting the T separator between date and time: 2024-03-15 14:30
- Using 12-hour time with AM/PM: 2:30 PM instead of 14:30
- Providing incomplete values: 2024-3-5 instead of 2024-03-05 (months and days must be zero-padded)
Examples
Invalid: Slash-separated date
<time datetime="03/15/2024">March 15, 2024</time>
Valid: ISO 8601 date format
<time datetime="2024-03-15">March 15, 2024</time>
Invalid: Missing T separator and using AM/PM
<time datetime="2024-03-15 2:30 PM">March 15 at 2:30 PM</time>
Valid: Date-time with T separator and 24-hour time
<time datetime="2024-03-15T14:30">March 15 at 2:30 PM</time>
Invalid: Informal time string
<time datetime="half past two">2:30 PM</time>
Valid: Simple time value
<time datetime="14:30">2:30 PM</time>
Invalid: Non-standard duration
<time datetime="1 hour 30 minutes">1.5 hours</time>
Valid: ISO 8601 duration
<time datetime="PT1H30M">1.5 hours</time>
Valid: Date-time with timezone offset
<p>The event starts at <time datetime="2024-03-15T14:30-05:00">2:30 PM ET on March 15</time>.</p>
Valid: Using only the month
<p>Published in <time datetime="2024-03">March 2024</time>.</p>
Remember that the human-readable text content between the <time> tags can be in any format you like — it’s only the datetime attribute value that must follow the specification. This lets you display dates in a user-friendly way while still providing a standardized machine-readable value.
Ready to validate your sites?
Start your free trial today.