Skip to content

formatX12Date

  • Container free time, demurrage, billing deadlines, bill of lading dates and EDI timestamps.
formatX12Date(value: string, format: X12DateFormat): string

Write an ISO 8601 date as an X12 Date Time Period value (data element 1251) in a date format qualifier (data element 1250). The inverse of parseX12Date.

  • Codes are release 005010, read from Stedi’s X12-licensed dictionary; the X12 text itself was not reached. ### Format codes

    CodeMaskThe dictionary’s definition
    D8CCYYMMDD“Date Expressed in Format CCYYMMDD”
    DBMMDDCCYY“Date Expressed in Format MMDDCCYY”
  • 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.

  • D8 also writes data element 373 (Date), the CCYYMMDD date element of AT7, G62 and DTM-02.

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

ParameterTypeDescription
valuestringISO 8601 date (e.g. “2024-06-15”)
formatX12DateFormatX12 data element 1250 format qualifier

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

import { formatX12Date } from "@northguild/gmt/intermodal/format";
formatX12Date("2024-06-15", "D8") // "20240615"
output 

intermodal/format/formatX12Date.ts