# Compact Year-Month (YYYYMM)

Key: `datetime.date.compact_ym`

6-digit compact year-month with no separators. Data warehouse period keys, financial reporting codes. Could collide with 6-digit integers — requires header/context hints.

Page: <https://meridian.online/docs/projects/finetype/types/datetime/date/compact_ym>

Format: `%Y%m`

Samples: `202401`, `202312`, `200006`

## Background

### Origin

FineType defines Compact Year-Month (YYYYMM) as a 6-digit compact year-month with no separators.[[1]](https://raw.githubusercontent.com/meridian-online/finetype/main/labels/definitions_datetime.yaml) FineType's definition names data warehouse period keys and financial reporting codes as where the format is found.[[1]](https://raw.githubusercontent.com/meridian-online/finetype/main/labels/definitions_datetime.yaml) FineType gives the type the format string %Y%m.[[1]](https://raw.githubusercontent.com/meridian-online/finetype/main/labels/definitions_datetime.yaml)

When the day is omitted from an ISO 8601 calendar date, only the YYYY-MM format is allowed.[[2]](https://en.wikipedia.org/wiki/ISO_8601) By disallowing dates of the form YYYYMM, ISO 8601 avoids confusion with the truncated representation YYMMDD.[[2]](https://en.wikipedia.org/wiki/ISO_8601) A YYYYMM value is best read as a convention of the system that wrote it, not as ISO 8601 with the hyphen dropped. (Meridian's view)

### Use

SAS's YYMMN informat reads date values in the form yyyymm or yymm.[[3]](https://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/p13mkc7m059u4kn1knl9nzpliaat.htm) The N in the YYMMN informat name indicates that the year and month cannot be separated by blanks or by special characters.[[3]](https://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/p13mkc7m059u4kn1knl9nzpliaat.htm) SAS automatically adds a day value of 01 when the YYMMN informat reads a year and month.[[3]](https://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/p13mkc7m059u4kn1knl9nzpliaat.htm) In the SAS documentation's example, the YYMMN6. informat reads the data line 201208 as the SAS date value 19206.[[3]](https://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/p13mkc7m059u4kn1knl9nzpliaat.htm)

Python's datetime.strptime pulls any component not specified in the format string from the default value 1900-01-01T00:00:00.000.[[4]](https://docs.python.org/3/library/datetime.html) Python's strptime treats the leading zero as optional for the %m format code.[[4]](https://docs.python.org/3/library/datetime.html) Check that every value is exactly six characters long before parsing, rather than trusting the parser to reject a short one. (Meridian's view)

A six-digit period key looks just like an ordinary integer, so read the column header and the spread of values before calling the column a date. (Meridian's view) Load the column as text, and convert it to a date only once you have confirmed every month falls between 01 and 12. (Meridian's view) When you do convert, record which day you used to stand for the whole month, since a month-start date and a month-end reporting date answer different questions. (Meridian's view)

### Where you'll meet it

The NSW Department of Communities and Justice is the stewardship organisation for a data element named Service episode: Reporting period, Date YYYYMM.[[5]](https://www.metadata.nsw.gov.au/item/3683) Metadata.NSW defines the service episode reporting period as the calendar month and year during which service episode information is collected, represented as YYYYMM.[[5]](https://www.metadata.nsw.gov.au/item/3683) Metadata.NSW gives the service episode reporting period a maximum character length of 6.[[5]](https://www.metadata.nsw.gov.au/item/3683)

## Sources

1. [definitions\_datetime.yaml](https://raw.githubusercontent.com/meridian-online/finetype/main/labels/definitions_datetime.yaml) — FineType
2. [ISO 8601 - Wikipedia](https://en.wikipedia.org/wiki/ISO_8601) — secondary source
3. [YYMMN Informat :: SAS(R) 9.4 Formats and Informats: Reference](https://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/p13mkc7m059u4kn1knl9nzpliaat.htm) — documentation
4. [datetime — Basic date and time types](https://docs.python.org/3/library/datetime.html) — documentation
5. [Service episode: Reporting period, Date YYYYMM (Data Element) - Metadata.NSW](https://www.metadata.nsw.gov.au/item/3683) — organisation
