# isValidX12Date

Industry: Intermodal

## Signature

```ts
isValidX12Date(value: string, format: X12DateFormat): boolean
```

Return true when `value` is an X12 Date Time Period value (data element 1251) that states a real calendar date in a date format qualifier (data element 1250).

- ### Format codes

  | Code | Mask | The dictionary's definition |
  |---|---|---|
  | `D8` | `CCYYMMDD` | "Date Expressed in Format CCYYMMDD" |
  | `DB` | `MMDDCCYY` | "Date Expressed in Format MMDDCCYY" |

- True exactly when `parseX12Date` returns a date for the same arguments: the validator and the parser share the parser, so the two cannot disagree.
- A value is valid only against its code: `"06152024"` is a `DB` value and not a `D8` one.
- Checks the calendar as well as the shape: 31 June and 29 February 2023 are false.
- False for any other code, a code of another kind included; check a code alone with `isValidX12DateTimePeriodFormat`. False for a non-string argument.

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `value` | `string` | The data element 1251 value (e.g. "20240615") |
| `format` | `X12DateFormat` | X12 data element 1250 format qualifier |

## Returns

boolean indicating validity

## Related types

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

## Examples

```ts
import { isValidX12Date } from "@northguild/gmt/intermodal/validate";

isValidX12Date("20240615", "D8") // true
```

## Source

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