> ## Documentation Index
> Fetch the complete documentation index at: https://validity-kt.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Date formats

> Text that holds an ISO 8601 date, time, date-time or duration, or a date in a pattern of yours.

Text that holds a date or a time, checked without converting it. To validate the date itself, such as "not in the
future", [convert it](https://validity-kt.dev/guides/converting-values.md) with `convertToLocalDate { }` instead.

```kotlin ImportRow.kt theme={null}
data class ImportRow(
    val createdOn: String?,
    val legacyDate: String? = null,
    val retention: String? = null
) : Validatable {
    override fun validation() = validation {
        ::createdOn required { isoDate() }
        ::legacyDate ifPresent { dateFormat("dd/MM/yyyy") }
        ::retention ifPresent { isoDuration() }
    }
}
```

| Constraint | Checks |
| - | - |
| [`isoDate`](#isodate) | Is an ISO 8601 date, such as `2024-02-29`, that exists in the calendar. |
| [`isoTime`](#isotime) | Is an ISO 8601 time, such as `13:45` or `13:45:30.5`, with no offset. |
| [`isoDateTime`](#isodatetime) | Is an ISO 8601 date and time with an offset, such as `2024-02-29T13:45:30Z` or `2024-02-29T13:45:30+01:00`. |
| [`isoDuration`](#isoduration) | Is an ISO 8601 duration, such as `P1Y2M`, `P3W` or `PT1H30M`. |
| [`dateFormat`](#dateformat) | Is a date or time written exactly in `pattern`. |

## ISO 8601

### `isoDate`

`isoDate()` on `String`

Checks that the string is an ISO 8601 date, such as `2024-02-29`, that exists in the calendar.

**Code** `isoDate`· **Message** `must be an ISO 8601 date` · **Change it** `isoDate = "…"`

### `isoTime`

`isoTime()` on `String`

Checks that the string is an ISO 8601 time, such as `13:45` or `13:45:30.5`, with no offset.

**Code** `isoTime`· **Message** `must be an ISO 8601 time` · **Change it** `isoTime = "…"`

### `isoDateTime`

`isoDateTime()` on `String`

Checks that the string is an ISO 8601 date and time with an offset, such as `2024-02-29T13:45:30Z` or `2024-02-29T13:45:30+01:00`.

**Code** `isoDateTime`· **Message** `must be an ISO 8601 date and time with offset` · **Change it** `isoDateTime = "…"`

### `isoDuration`

`isoDuration()` on `String`

Checks that the string is an ISO 8601 duration, such as `P1Y2M`, `P3W` or `PT1H30M`.

**Code** `isoDuration`· **Message** `must be an ISO 8601 duration` · **Change it** `isoDuration = "…"`

## Patterns

### `dateFormat`

`dateFormat(pattern)` on `String`

Checks that the string is a date or time written exactly in `pattern`.

The string is parsed with `DateTimeFormatter.ofPattern` and must print back the same, so `2024-2-9` does not match `yyyy-MM-dd`.

**Code** `dateFormat`· **Message** `must match the date format {pattern}` · **Change it** `dateFormat = "…"`


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.