# `HL7v2.Type.DT`
[🔗](https://github.com/Balneario-de-Cofrentes/hl7v2/blob/v3.10.1/lib/hl7v2/type/dt.ex#L1)

Date (DT) -- HL7v2 primitive data type.

Format: `YYYY[MM[DD]]`. Supports year, month, and day precision.
Parses to an `%HL7v2.Type.DT{}` struct preserving precision, or a `Date`
when full day precision is available.

# `t`

```elixir
@type t() :: %HL7v2.Type.DT{
  day: pos_integer() | nil,
  month: pos_integer() | nil,
  original: term(),
  year: pos_integer()
}
```

# `encode`

```elixir
@spec encode(Date.t() | t() | nil) :: binary()
```

Encodes a date value to `YYYYMMDD`, `YYYYMM`, or `YYYY` format.

## Examples

    iex> HL7v2.Type.DT.encode(~D[1988-07-04])
    "19880704"

    iex> HL7v2.Type.DT.encode(%HL7v2.Type.DT{year: 1995, month: 3})
    "199503"

    iex> HL7v2.Type.DT.encode(%HL7v2.Type.DT{year: 2026})
    "2026"

    iex> HL7v2.Type.DT.encode(nil)
    ""

# `parse`

```elixir
@spec parse(binary() | nil) :: Date.t() | t() | nil
```

Parses a date string in `YYYY[MM[DD]]` format.

Returns a `Date` struct when fully specified (8 digits), or an
`%HL7v2.Type.DT{}` struct for partial dates.

## Examples

    iex> HL7v2.Type.DT.parse("19880704")
    ~D[1988-07-04]

    iex> HL7v2.Type.DT.parse("199503")
    %HL7v2.Type.DT{year: 1995, month: 3, day: nil}

    iex> HL7v2.Type.DT.parse("2026")
    %HL7v2.Type.DT{year: 2026, month: nil, day: nil}

    iex> HL7v2.Type.DT.parse("")
    nil

    iex> HL7v2.Type.DT.parse(nil)
    nil

---

*Consult [api-reference.md](api-reference.md) for complete listing*
