# formatEdifactDateTime

Industry: Intermodal

## Signature

```ts
formatEdifactDateTime(value: string, format: EdifactDateTimeFormat): string
```

Write an ISO 8601 local date-time as a UN/EDIFACT `DTM` value (data element 2380) in a format code with no offset (data element 2379). The inverse of `parseEdifactDateTime`.

- Masks and descriptions 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 codes

  | Code | Mask | The directory's description |
  |---|---|---|
  | `203` | `CCYYMMDDHHMM` | "Calendar date including time with minutes" |
  | `204` | `CCYYMMDDHHMMSS` | "Calendar date including time with seconds" |

- `value` is a local date-time, as `isValidDateTime` accepts it. A date, a time, an instant ending in `Z` and a date-time with an offset return `""`: these codes hold no offset. Write an instant with `formatEdifactOffsetDateTime`.
- Precision is cut to the mask, never rounded: a fraction of a second is always dropped, and `203` drops the seconds too. `2024-06-15T14:30:45.9` is `202406151430` under `203` and `20240615143045` under `204`.
- A year outside 0000–9999 returns `""`: `CCYY` is four digits and no sign.
- 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 local date-time (e.g. "2024-06-15T14:30:00") |
| `format` | `EdifactDateTimeFormat` | The data element 2379 format code |

## Returns

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

## Related types

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

## Examples

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

formatEdifactDateTime("2024-06-15T14:30:00", "203") // "202406151430"
```

## Source

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