# formatEdifactDate

Industry: Intermodal

## Signature

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

Write an ISO 8601 date as a UN/EDIFACT `DTM` value (data element 2380) in a date format code (data element 2379). The inverse of `parseEdifactDate`: what one writes, the other reads back.

- 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." |

- `value` is a date, as `isValidDate` accepts it. A date-time, an instant or a time returns `""`, as `formatDate` returns `""` for them: pass the date alone.
- Each field is zero-padded to the width the mask gives it.
- A year outside 0000–9999 returns `""`: `CCYY` is four digits and no sign.
- No function writes a two-digit year (`101`, `YYMMDD`): the one date code that is written holds the whole year.
- Returns `""` for any other code, a code of another kind included, and for a non-string argument.

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `value` | `string` | ISO 8601 date (e.g. "2024-06-15") |
| `format` | `"102"` | The data element 2379 format code |

## Returns

the data element 2380 value, or "" on invalid input

## Related types

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

## Examples

```ts
import { formatEdifactDate } from "@northguild/gmt/intermodal/format";

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

## Source

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