# formatX12DateTimeRange

Industry: Intermodal

## Signature

```ts
formatX12DateTimeRange(start: string, end: string, format: X12DateTimeRangeFormat): string
```

Write two ISO 8601 local date-times as an X12 Date Time Period range (data element 1251) in a date-time range format qualifier (data element 1250). The inverse of `parseX12DateTimeRange`.

- Codes are release 005010, read from [Stedi's X12-licensed dictionary](https://www.stedi.com/edi/x12-005010/element/1250); the X12 text itself was not reached. ### Format codes

  | Code | Mask | The dictionary's definition |
  |---|---|---|
  | `RDT` | `CCYYMMDDHHMM-CCYYMMDDHHMM` | "Range of Date and Time, Expressed in Format CCYYMMDDHHMM-CCYYMMDDHHMM" |
  | `DTS` | `CCYYMMDDHHMMSS-CCYYMMDDHHMMSS` | "Range of Date and Time Expressed in Format CCYYMMDDHHMMSS-CCYYMMDDHHMMSS" |

- `start` and `end` are local date-times, as `isValidDateTime` accepts them: the two members `parseX12DateTimeRange` returns. A date, an instant ending in `Z` and a date-time with an offset return `""`: no 1250 code carries an offset.
- **The range is written with the one hyphen X12 transmits.**
- Precision is cut to the mask, never rounded: a fraction of a second is always dropped from both ends, and `RDT` drops the seconds too.
- **An end before its start returns `""`**: a reversed range names no span of time. The ends are compared as given, before either is cut to the mask. An end equal to its start is written.
- A year outside 0000–9999 in either end 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 local date-time the range starts at (e.g. "2024-06-15T14:30:00") |
| `end` | `string` | ISO 8601 local date-time the range ends at (e.g. "2024-06-20T16:00:00") |
| `format` | `X12DateTimeRangeFormat` | X12 data element 1250 format qualifier |

## Returns

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

## Related types

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

## Examples

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

formatX12DateTimeRange("2024-06-15T14:30:00", "2024-06-20T16:00:00", "RDT") // "202406151430-202406201600"
```

## Source

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