# Bad value X for attribute “datetime” on element “time”: The literal did not satisfy the time-datetime format.

> Canonical HTML version: https://rocketvalidator.com/html-validation/bad-value-x-for-attribute-datetime-on-element-time-the-literal-did-not-satisfy-the-time-datetime-format
> Attribution: Rocket Validator (https://rocketvalidator.com)
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)

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

```html
<time datetime="03/15/2024">March 15, 2024</time>
```

### Valid: ISO 8601 date format

```html
<time datetime="2024-03-15">March 15, 2024</time>
```

### Invalid: Missing `T` separator and using AM/PM

```html
<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

```html
<time datetime="2024-03-15T14:30">March 15 at 2:30 PM</time>
```

### Invalid: Informal time string

```html
<time datetime="half past two">2:30 PM</time>
```

### Valid: Simple time value

```html
<time datetime="14:30">2:30 PM</time>
```

### Invalid: Non-standard duration

```html
<time datetime="1 hour 30 minutes">1.5 hours</time>
```

### Valid: ISO 8601 duration

```html
<time datetime="PT1H30M">1.5 hours</time>
```

### Valid: Date-time with timezone offset

```html
<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

```html
<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.
