How to: |
Reference: |
Available Languages: reporting, Maintain
The CHGDAT function rearranges the year, month, and day portions of an input character string representing a date. It may also convert the input string from long to short or short to long date representation. Long representation contains all three date components: year, month, and day; short representation omits one or two of the date components, such as year, month, or day. The input and output date strings are described by display options that specify both the order of date components (year, month, day) in the date string and whether two or four digits are used for the year (for example, 04 or 2004). CHGDAT reads an input date character string and creates an output date character string that represents the same date in a different way.
Note: CHGDAT requires a date character string as input, not a date itself. Whether the input is a standard or legacy date, convert it to a date character string (using the EDIT or DATECVT functions, for example) before applying CHGDAT.
The order of date components in the date character string is described by display options comprised of the following characters in your chosen order:
Character |
Description |
---|---|
D |
Day of the month (01 through 31). |
M |
Month of the year (01 through 12). |
Y[Y] |
Year. Y indicates a two-digit year (such as 94); YY indicates a four-digit year (such as 1994). |
To spell out the month rather than use a number in the resulting string, append one of the following characters to the display options for the resulting string:
Character |
Description |
---|---|
T |
Displays the month as a three-letter abbreviation. |
X |
Displays the full name of the month. |
Display options can consist of up to five display characters. Characters other than those display options are ignored.
For example: The display options 'DMYY' specify that the date string starts with a two digit day, then two digit month, then four digit year.
Note: Display options are not date formats.
If you are converting a date from short to long representation (for example, from year-month to year-month-day), the function supplies the portion of the date missing in the short representation, as shown in the following table:
Portion of Date Missing |
Portion Supplied by Function |
---|---|
Day (for example, from YM to YMD) |
Last day of the month. |
Month (for example, from Y to YM) |
Last month of the year (December). |
Year (for example, from MD to YMD) |
The year 99. |
Converting year from two-digit to four-digit (for example, from YMD to YYMD) |
The century will be determined by the 100-year window defined by DEFCENT and YRTHRESH. See Customizing Your Environment in the TIBCO WebFOCUS® Developing Reporting Applications manual or Working With Cross-Century Dates in the iBase archive for details on DEFCENT and YRTHRESH. |
CHGDAT('in_display_options','out_display_options',date_string,output)
where:
A1 to A5
Is a series of up to five display options that describe the layout of date_string. These options can be stored in an alphanumeric field or supplied as a literal enclosed in single quotation marks.
A1 to A5
Is a series of up to five display options that describe the layout of the converted date string. These options can be stored in an alphanumeric field or supplied as a literal enclosed in single quotation marks.
A2 to A8
Is the input date character string with date components in the order specified by in_display_options.
Note that if the original date is in numeric format, you must convert it to a date character string. If date_string does not correctly represent the date (the date is invalid), the function returns blank spaces.
Axx, where xx is a number of characters large enough to fit the date string specified by out_display_options. A17 is long enough to fit the longest date string.
Is the name of the field that contains the result, or the format of the output value enclosed in single quotation marks.
Note: Since CHGDAT uses a date string (as opposed to a date) and returns a date string with up to 17 characters, use the EDIT or DATECVT functions or any other means to convert the date to or from a date character string.
The EDIT function changes HIRE_DATE from numeric to alphanumeric format. CHGDAT then converts each value in ALPHA_HIRE from displaying the components as YMD to MDYYX and stores the result in HIRE_MDY, which has the format A17. The option X in the output value displays the full name of the month.
TABLE FILE EMPLOYEE PRINT HIRE_DATE AND COMPUTE ALPHA_HIRE/A17 = EDIT(HIRE_DATE); NOPRINT AND COMPUTE HIRE_MDY/A17 = CHGDAT('YMD', 'MDYYX', ALPHA_HIRE, 'A17'); BY LAST_NAME BY FIRST_NAME WHERE DEPARTMENT EQ 'PRODUCTION'; END
The output is:
LAST_NAME FIRST_NAME HIRE_DATE HIRE_MDY --------- ---------- --------- -------- BANNING JOHN 82/08/01 AUGUST 01 1982 IRVING JOAN 82/01/04 JANUARY 04 1982 MCKNIGHT ROGER 82/02/02 FEBRUARY 02 1982 ROMANS ANTHONY 82/07/01 JULY 01 1982 SMITH RICHARD 82/01/04 JANUARY 04 1982 STEVENS ALFRED 80/06/02 JUNE 02 1980