Date Conversion (D)

Date Conversion (D)

Top  Previous  Next


Inside QM, dates are stored as a number of days since 31 December 1967 (day zero). All dates after that point are represented by positive numbers. All dates before that point are represented by negative numbers.


The date conversion code converts a date from its internal day number to one of a number of external formats or vice versa.


The full format of this conversion code is


D {y} {c} {fmt} {[f1, f2, f3, f4, f5]}




yis a digit in the range 0 to 4 specifying the number of digits to appear in the year number. This defaults to 4.


cis the character to be used to separate the year, month and day components of the converted date. If omitted, a space is used. Specifying c as the digit 0 suppresses insertion of a separator between the year, month and day components. The same effect can be achieved by use of a null separator text string in the format modifiers (e.g. DYMD["",""])


fmtspecifies the components to be present in the converted date. Multiple characters may be chosen from the following list subject to restrictions shown below. If fmt is omitted it defaults to MDY if American date mode is in use or DMY if European date mode is in use.
DDay of month.
DOOrdinal day of month (1st, 2nd, 3rd, etc)
EToggles European date format (day, month, year). See also DATE.FORMAT.
JJulian date (days since the start of the year).
LAlphabetic month and day names are to appear with only the first character in uppercase instead of entirely in uppercase.
MMonth in format determined by format modifiers. If no format modifiers are present, a two digit month number is used unless c is present in which case a three letter alphabetic month is used.
MAMonth name.
MBBrief month name.
QQuarter number (1 to 4).
WDay of week number. Monday is day 1, Sunday is day 7.
WAWeekday name.
WBBrief weekday name.
WIISO week number.
XANSI X12 format date (YYYYMMDD with no separators).
YIISO year number. This is not always the same as the calendar year as a date may be in the last week of the previous ISO year or in the first week of the following ISO year.



[f1,f2,f3,f4,f5]These format modifiers affect the way in which the above formats are handled. Up to five modifiers may be specified and they are associated with the formats in the order in which they appear in fmt. Format modifiers are
nUse n characters.
ADisplay as alphabetic (applies to month component only).
AnDisplay as n alphabetic characters (applies to month component only).
ZSuppress leading zeros.
ZnDisplay as n digits with leading zeros replaced by spaces.
"text"Uses the supplied text as the separator after the associated component.
n"text"Use n characters and then use the supplied text as the separator after the associated component.


The following special codes are recognised as part of the D conversion code for ISO8601 format output. These may not be used with any other conversion elements:



Four digit year number, two digit ISO week number, one digit day of week.



Four digit year number, two digit ISO week number, one digit day of week with hyphen separators.



Output Conversion of Dates


The following examples show the result of output conversion of a value of 9649 with various conversion codes. Where affected by DATE.FORMAT setting, both forms are shown.




European date


01 JUN 1994



01 JUN 94



01 JUN 1994





'D '

06 01 1994

01 06 1994







'D2 E'

01 06 94

06 01 94








1994 06 01











'D MY[A,2]'




1st June 1994


'D DMY[,A3,2]'

01 JUN 94


'D DMY[,A9,2]'

01 JUNE      94





'D DMYL[,A,]'

01 June 1994



1 June 94



94 06 01
































Input Conversion of Dates


Alphabetic month names may be supplied in the external format date. At least three letters must be present and conversion is not case sensitive. If more than three letters are present, the must correctly match the spelling of the month name.


The date conversion system allows some flexibility to the order in which the components of the date may occur in the input data. Where an alphabetic month name is used, this is processed first. Numeric components are then assumed to be in the order of the remaining elements of the conversion code. Thus with a code of DDMY, '1 Jun 94' and 'Jun 1 94' would both convert to 9649, the internal representation of 1 June 1994.


A date that is entered as a simple digit sequence with no separators (e.g. 020609) will be treated as being day, month and year components in the order defined by the fmt element of the conversion code, with a maximum of two digits in the day and month. The year component will be processed as having the number of digits in the conversion code, defaulting to 4. A trailing year with only two digits will follow the normal rules as described in the next paragraph.


For dates entered as two digits, year number values in the range 30 to 99 are assumed to be 1930 to 1999 and 0 to 29 are assumed to be 2000 to 2029. This 100 year window can be moved using the YEARBASE configuration parameter.


Where not included, the day number or month number is assumed to be one and the year number to be the current year.


For compatibility with Information style multivalue products, a day number that exceeds the number of days in the month will roll forward into the next month and return a value of 3 from the STATUS() function. This feature can be suppressed by enabling the NO.DATE.WRAPPING mode of the OPTION command.



Alphabetic Day and Month Names


The strings used for the alphabetic day and month names are derived from the QM messages file and can be different based on language selection. The relevant message numbers are






Alphabetic month



Brief alphabetic month



Alphabetic day of week



Brief alphabetic day of week


In addition, message 1502 defines the ordinal numeric strings used by the DO code.



Calendar Differences


The process of converting an external format date to its internal day number and vice versa is not as easy as it sounds. As well as the slightly complex rules that determine which years are leap years and hence have 29 days in February, there is a problem of calendar differences. Most of the world now uses the same calendar for business purposes but this has not always been the case. There were two significant realignments, one in 1752 and an earlier one in 1583 in different parts of the world. Prior to these changes, the date in one country could be several days different from that elsewhere.


The QM date conversion operations assume the current calendar system and make no adjustment to handle these realignments. Some multivalue products implement one or other realignment. Whichever system is used, it will be incorrect in some contexts. Users who require specific handling of these changes or need to handle dates before 1 January 0001 will need to develop their own date conversion functions.



See also:

Dates, Times and Epoch Values