edifact/eancom DTM to timestamp parsing(format a, value b, part c, [time zone d, locale e, exception handling f, force empty g])

Prev Next

Reads the date and time encoded in the value b of a EDIFACT or EANCOM DTM segment and returns it as a timestamp. The DTM format code a (data element 2379) specifies how the value b is interpreted.

Example: In DTM+137:20240302:102', the value is 20240302 and the format code is 102.

The following rules apply during processing:

  • Format codes that describe a time period (e.g., 718) contain two date components. The parameter c selects which component is returned. For all other format codes, c has no effect.

  • The time zone d is used only for values that do not themselves contain a time zone. If the format code contains a time zone (e.g., 205, 304, 406), the time zone contained in the value is used and d is ignored.

  • The locale e applies only to format codes based on calendar weeks (103, 104, 615, 616, 715, 716). Without a locale, the EDIFACT rules apply: The week begins on Monday, and week 1 is the week that includes January 1. With a locale, its week rules apply (for de_DE, the ISO 8601 rules, where week 1 is the first week with at least four days in the new year).

  • Two-digit years (YY) are assigned to the century that falls within the range of 80 years before to 20 years after the current date. In 2026, 99 therefore refers to 1999, and 12 refers to the year 2012.

  • The time zone sign can be written as + or -, or, as is customary in EDIFACT, as P (plus) and M (minus).

  • Leading and trailing spaces in format code a and value b are removed; case is not significant.

Parameter

Parameter

Description

a

DTM format code (data element 2379), e.g., 102, 203, 718. See the "Format codes" section below.

b

The value from the DTM segment to be processed.

c

(optional) Part of a time period that is returned. from, 1, true, or empty specify the start; until, 2, or false specify the end. Relevant only for format codes that describe a time period. Default: from.

d

(optional) Time zone for values that do not contain their own time zone. Valid values include time zone IDs such as Europe/Berlin, America/New_York, UTC, or GMT+03:30; an EDIFACT offset such as +0330, P0330, -0330, M0330, +03, or M03, the value SYSTEM (server time zone), or a date/time stamp field, in which case that field’s time zone is used. Ambiguous abbreviations such as CET should be avoided. Default: server time zone.

e

(optional) Locale for calendar week rules, e.g., de_DE or en_US. If not specified, the EDIFACT week rules apply (the week begins on Monday; week 1 includes 1 January). Default: EDIFACT rules.

f

(optional) Error handling if b cannot be processed using the format code a.

  • error – Termination with an error message.

  • empty – The result is an empty timestamp with the Empty flag set.

  • now – The result is the current date and time.

Default: error

g

(optional) Forces an empty value. If true, the function immediately returns an empty value with the empty flag set, without processing b – for example, if the source field is empty. Default: false

Format codes

Format codes are supported for calendar dates, dates with times (including time zones), times only, and time periods. Any components not included in the value are set to their lowest possible value: a missing time is set to 00:00:00, a missing day is set to the first day of the time period, and a missing year is set to 1970.

Format codes that represent a number rather than a date or time (107–110 and 801–814) are rejected. The function edifact/eancom DTM to number parsing is intended for these format codes.

For the complete definitions of all format codes, see the code list for UN/CEFACT data element 2379: UN/CEFACT UNCL 2379.

EANCOM also defines the following codes, which are not included in the UN code list:

Code

Value

Result

20E

CCYYMMDDHHMMCCYYMMDDHHMM

Date and time, such as 719

21E

DDHHMMDDHHMM

Day and time, in January 1970

22E

DHHMMDHHMM

Day of the week and time, such as 720

Examples

The server's time zone in the examples is Europe/Berlin. The time zone of the result is shown in brackets. The parameters f and g are empty unless otherwise specified.

Parameter a

Parameter b

Parameter c

Parameter d

Parameter e

Result

2

120215

UTC

2015-02-12 00:00:00.0 (UTC)

6

2015021

2015-02-01 00:00:00.0 (Europe/Berlin)

6

2015022

2015-02-15 00:00:00.0 (Europe/Berlin)

7

2024031

2024-02-26 00:00:00.0 (Europe/Berlin), The Monday of the week that includes 1 March

7

2024032

2024-03-04 00:00:00.0 (Europe/Berlin)

10

20030201T1234

2003-02-01 12:34:00.0 (Europe/Berlin)

102

20240301

2024-03-01 00:00:00.0 (Europe/Berlin)

103

21023

2021-01-06 00:00:00.0 (Europe/Berlin), EDIFACT-weekly rules

103

21023

de_DE

2021-01-13 00:00:00.0 (Europe/Berlin), ISO-weekly rules

105

24366

2024-12-31 00:00:00.0 (Europe/Berlin)

203

202403021345

2024-03-02 13:45:00.0 (Europe/Berlin)

204

20010203123456

UTC

2001-02-03 12:34:56.0 (UTC)

205

202403021345+0300

2024-03-02 13:45:00.0 (GMT+03:00)

205

202403021345P0300

2024-03-02 13:45:00.0 (GMT+03:00)

205

202403310230M0300

UTC

2024-03-31 02:30:00.0 (GMT-03:00), d is ignored

301

0102031234+03

2001-02-03 12:34:00.0 (GMT+03:00)

307

20010203123456123

2001-02-03 12:34:56.123 (Europe/Berlin)

401

1234

1970-01-01 12:34:00.0 (Europe/Berlin)

405

123456

1970-01-01 20:34:56.0 (Europe/Berlin)

406

+0330

1970-01-01 00:00:00.0 (GMT+03:30)

501

12342345

until

1970-01-01 23:45:00.0 (Europe/Berlin)

608

20123

2012-07-01 00:00:00.0 (Europe/Berlin)

613

21023

2021-02-21 00:00:00.0 (Europe/Berlin)

615

2102

2021-01-04 00:00:00.0 (Europe/Berlin), EDIFACT-weekly rules

615

2102

de_DE

2021-01-11 00:00:00.0 (Europe/Berlin), ISO-weekly rules

718

2001020319040506

from

2001-02-03 00:00:00.0 (Europe/Berlin)

718

2001020319040506

until

1904-05-06 00:00:00.0 (Europe/Berlin)

719

202403021345190102032343

1

2024-03-02 13:45:00.0 (Europe/Berlin)

719

202403021345190102032343

2

1901-02-03 23:43:00.0 (Europe/Berlin)

720

1234520123

from

1970-01-05 23:45:00.0 (Europe/Berlin), Monday

720

1234520123

until

1970-01-06 01:23:00.0 (Europe/Berlin), Tuesday

Error handling

Parameter a

Parameter b

Parameter d

Parameter f

Parameter g

Result

7

2027025

Termination due to error invalid week value for "2027025" with format code "7": 5 (February 2027 has only four weeks).

102

20031301

Terminated with error unable to parse "20031301" with format code "102" (month 13).

102

ABC

now

Current date and time.

102

true

An empty value, b, is not processed.

203

202403310230

The process was terminated due to an error because 2:30 a.m. on 31 March 2024 does not exist in Europe/Berlin (daylight saving time transition).

203

202403310230

UTC

2024-03-31 02:30:00.0 (UTC)

801

12

Terminated with error unable to parse "12" with format code "801", because the code represents a number.

801

12

empty

An empty timestamp with the empty flag set.