Skip to content

8: New dateTime data type

Fabian Depry edited this page May 23, 2024 · 4 revisions

Specifications 1.8 introduced a new data type dateTime.

Note that the existing date data type is still very much in use for most of the defined date data items, and there is no plan to change that. Only a few data items were changed in NAACCR 25 to start using this new type.

The goal of the new type is to transmit date values that include a time portion.

The data type is based on the well accepted ISO 8601 format that allows timestamps to be provided based on UTC (Universal Time Coordinated).

It aligns with the FHIR dateTime format which is itself a subset of the ISO 8601 specifications. Unlike the FHIR format, NAACCR XML doesn't allow fractions of a second to be provided.

The following describes the new format:

  • Year, month and day are separated by a deash (year must be 4 digits, month and day must be 2 digits)
  • Month and day are optional (if day is provided, month must be provided as well).
  • The time portion is separated by the letter 'T'.
  • If a time portion is provided, a time zone must be provided.
  • Hour, minute and seconds are separated by a colon (they must all be 2 digits).
  • Fractions of a second (which is a dot followed by 1 to 9 digits for different precisions) is not allowed in NAACCR XML.
  • Time zone can be the letter 'Z' (representing UTC time), or an offset of UTC (plus/minus a number of hours and minutes).

The minimum length of dateTime values is 4 (for a single year) while the maximum length is 25 (for a full date and time with a UTC offset).

Note that this new data type is not compatible with the simpler date data type (which is 4, 6 or 8 digits) because this new one uses dashes between the year, month and day. But as mentioned earlier, the existing date data type is still very much in use for most of the defined date data items, and there is no plan to retire it.

The following regular expression can be used to validate the new data type:

([0-9]([0-9]([0-9][1-9]|[1-9]0)|[1-9]00)|[1-9]000)(-(0[1-9]|1[0-2])(-(0[1-9]|[1-2][0-9]|3[0-1])(T([01][0-9]|2[0-3]):[0-5][0-9]:([0-5][0-9]|60))?)?(Z|([+-])((0[0-9]|1[0-3]):[0-5][0-9]|14:00)?)?)?

The following are valid values:

  • 2010 (year only)
  • 2010-06 (year and month)
  • 2010-06-15 (year, month and day, but no time)
  • 2010-06-15T13:45:30Z (UTC)
  • 2010-06-15T13:45:30-04:00 (UTC minus 4 hours)
  • 2010-06-15T13:45:30+05:30 (UTC plus 5 1/2 hours)

The following are invalid values:

  • 20100615 (format requires dashes)
  • 10 (year needs to be 4 digits)
  • 2010-6-15 (month needs to be two digits)
  • 2010-06-1 (day needs to be two digits)
  • 2010-06- (no missing parts allowed)
  • 2010- -15 (no missing parts allowed)
  • 06-15 (no missing parts allowed)
  • XYZ (garbage)
  • 2010-06-15! (garbage)
  • 2010-13-15 (invalid month)
  • 2010-06-32 (invalid day)
  • 2010-99-99 (invalid month and day)
  • 2010-06-15T14:10:30 (time zone is required if time is provided)
  • 2010-06-15TZ (missing hours)
  • 2010-06-15T21Z (missing minutes)
  • 2010-06-15T21:32Z (missing seconds)
  • 2010-06-15T25:32:52+02:00 (wrong hour)
  • 2010-06-15T1:45:30Z (hours need to be 2 digits)
  • 2010-06-15T13:45:30+2:00 (timezone requires 2 digits)
  • 2010-06-15T00:00:30.000Z (no second fraction allowed)
  • 2010-06-15T13:45:30.001-05:00 (no second fraction allowed)
  • 2010-06-15T13:45:30.0-05:00 (no second fraction allowed)
  • 2010-06-15T13:45:30.000000001-05:00 (no second fraction allowed)
Clone this wiki locally