Date Conversion With ICONV
Dates in the real world can be in many different formats. The purpose of ICONV for dates is to convert them into a single internal format (number of days since 31 Dec 1967 - dates earlier than this are represented by negative integers), irrespective of the external format.
ICONV is extremely flexible. If the component ordering of the external date is the same as that of your locale, then the only specification needed is "D". For example:
ICONV("03-15-02", "D")
is effective in locales where the default order is month-day-year.
If the component ordering in the external date is different from that of your locale, you need only specify the component markers. Irrespective of the actual delimiters in the external format, ICONV will cope. For example:
ICONV("2002-03-15", "DYMD")
is sufficient; it is not necessary - though not wrong - to specify "-" as the delimiter character, even though it is not the default delimiter character for dates. ICONV("2002.03.15", "DYMD") would work just as well.
Wholly Numeric Dates
There are specific rules for wholly numeric dates. ICONV with just "D" as the second argument will recognize wholly numeric dates between five and eight characters long, according to the following rules.
- yyjjj (two digit year, three digit ordinal day number)
- yymmdd (two digit year, two digit month number, two digit day number)
- yyyyjjj (four digit year, three digit ordinal day number)
- yyyymmdd (four digit year, two digit month number, two digit day number)
STATUS()
Following ICONV on a date, the STATUS() function may return one of four possible values.
- 0 the conversion was successful
- 1 the first argument is not a valid date
- 2 the second argument is not a valid specification
- 3 the first argument is not a valid date but was converted
To generate a value of 3, the date must resolve to having a day number in the range 29 through 31 which is not valid for the month in question, for example 31 Apr is converted to the equivalent of 01 May.
Back to Date Conversion Demystified
This material is copyright © 2003, Ray Wurlod. All rights reserved.