# formatEdifactDatePeriod

Industry: Intermodal

## Signature

```ts
formatEdifactDatePeriod(start: string, end: string, format: "718"): string
```

Write two ISO 8601 dates as a UN/EDIFACT `DTM` period (data element 2380) in a date period format code (data element 2379). The inverse of `parseEdifactDatePeriod`.

- 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 |
  |---|---|---|
  | `718` | `CCYYMMDD-CCYYMMDD` | "A period of time specified by giving the start date followed by the end date (both including century). Data is to be transmitted as consecutive characters without hyphen." |

- `start` and `end` are dates, as `isValidDate` accepts them: the two members `parseEdifactDatePeriod` returns. A date-time or an instant returns `""`.
- **The period is written without a hyphen**, as every directory read says it is transmitted: 15 to 20 June 2024 is `2024061520240620`.
- **An end before its start returns `""`**: a reversed period names no span of time. An end equal to its start is written.
- A year outside 0000–9999 in either date returns `""`.
- Returns `""` for any other code, a code of another kind included, and for a non-string argument.

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `start` | `string` | ISO 8601 date the period starts on (e.g. "2024-06-15") |
| `end` | `string` | ISO 8601 date the period ends on (e.g. "2024-06-20") |
| `format` | `"718"` | The data element 2379 format code |

## Returns

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

## Related types

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

## Examples

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

formatEdifactDatePeriod("2024-06-15", "2024-06-20", "718") // "2024061520240620"
```

## Source

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