# parseEdifactDate

Industry: Intermodal

## Signature

```ts
parseEdifactDate(value: string, format: "102"): string
```

Parse a UN/EDIFACT `DTM` value that states a calendar date, as an ISO 8601 date.

- A `DTM` segment carries its value in data element **2380** and, in data element **2379**, the format code that says how to read it. This function reads the code whose value is a date. The mask and description are the UNTDID directory's, read from [UNECE's D.21B page as archived](http://web.archive.org/web/20240303123657/https://service.unece.org/trade/untdid/d21b/tred/tred2379.htm). ### Format code

  | Code | Mask | The directory's description |
  |---|---|---|
  | `102` | `CCYYMMDD` | "Calendar date: C = Century ; Y = Year ; M = Month ; D = Day." |

- The value must be the eight digits of the mask and nothing else: a hyphen, a space or a ninth digit returns `""`.
- Fields are checked, not clamped: month 13, 31 June and 29 February 2023 return `""`.
- The year is the four digits as written, `0000` to `9999`.
- A two-digit year (`101`, `YYMMDD`) is not read: UN/EDIFACT does not say which century it belongs to. Read one with `parseDateWithPattern("240615", "yyMMdd", undefined, { yearWindow: 2000 })`.
- Returns `""` for any other code, a code of another kind included (`203` is read by `parseEdifactDateTime`); `classifyEdifactDtmFormat` names the kind of a code. Returns `""` for a non-string argument.

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `value` | `string` | The data element 2380 value (e.g. "20240615") |
| `format` | `"102"` | The data element 2379 format code |

## Returns

the date as `YYYY-MM-DD`, or "" on invalid input

## Related types

- [`EdifactDateFormat`](/gmt/reference/types/EdifactDateFormat/)

## Examples

```ts
import { parseEdifactDate } from "@northguild/gmt/intermodal/parse";

parseEdifactDate("20240615", "102") // "2024-06-15"
```

## Source

[intermodal/parse/parseEdifactDate.ts](https://github.com/northguild/gmt/blob/main/packages/gmt/src/intermodal/parse/parseEdifactDate.ts)
