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. This form of date is used by all multivalue databases and means that they had no issue with the millennium (day 11689). The multivalue world had its own date crisis on 18 May 1995 (day 10000) when developers discovered that they had stored the date as four characters of a composite record id or were sorting dates as character strings rather than numbers such that 17 May 1985 (day 9999) came after 18 May 1995. This potential problem still applies to any application that handles historic dates but the advantages of working with a simple day number internally far outweigh any disadvantages.

 

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]}

 

where

 

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.

 

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.
QQuarter number (1 to 4).
WDay of week number. Monday is day 1.
WAWeekday name.
WIISO week number.
YYear.
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.

 

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.

 

Code

Result

European date

'D'

01 JUN 1994

01 JUN 1994

'D2'

01 JUN 94

01 JUN 94

'D4'

01 JUN 1994

01 JUN 1994

'D/'

06/01/1994

01/06/1994

'D '

06 01 1994

01 06 1994

'D2/'

06/01/94

01/06/94

'D/E'

01/06/1994

06/01/94

'D2 E'

01 06 94

06 01 94

'D.YJ'

1994.152

 

'D2:JY'

152:94

 

'D YMD'

1994 06 01

 

'D MY[A,2]'

JUN 94

 

'D4DOMAYL'

1st June 1994

 

'D DMY[,A3,2]'

01 JUN 94

 

'D DMY[,A9,2]'

01 JUNE      94

 

'D/MDY[Z,Z,2]'

6/1/94

 

'D DMYL[,A,]'

01 June 1994

 

'DDMYL[Z,A,2]'

1 June 94

 

'DYMD[2,2,2]'

94 06 01

 

'DW'

3

 

'DWA'

WEDNESDAY

 

'DWAL'

Wednesday

 

'DMA'

JUNE

 

'DMAL'

June

 

'DQ'

2

 

'D-YIWI'

1994-22


 

 

 

Input Conversion of Dates

 

Alphabetic month names may be supplied in the external format date. At least three letter 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. Where an alphabetic month name is used, the day and month fields of the external format date may be interchanged. Thus '1 Jun 94' and 'Jun 1 94' would both convert to 9649, the internal representation of 1 June 1994.

 

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

 

 

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.