Date to Character

DateToChar - Convert Date to Character

The DateToChar procedure returns the date as an character string. The returned date format is specified on the second parameter of this procedure.

The DateToChar procedure gives you the same capability as the %CHAR() built-in function, plus much more. In addition to the standard, fixed date formatting codes, you may also specify custom formatting codes to provide you with even more options.

 result-character-string  =  DateToChar(
  InDate              D     Const DATFMT(*ISO)
  szFmt             64A     Const VARYING Options(*NOPASS)
)

See also: CvtDateString DateToDec

Parameters

InDate 
[input DATE(*ISO) const]  The date (in any date format) that will be converted to character.

szFmt [optional]
[input const]  An optional date formatting code that indicates the format into which the date will be converted. An optional separator character may be specified in the final position of the szFMT parameter. if specified, this value overrides the default separator for the indicated date format code. If a value of zero (e.g. *YMD0) is specified for the separator, then no separator is inserted into the resulting value.
 

szFmt Options

The szFmt parameter may contain any of the following values:

Formatting Options Resulting Date Format
*ISO YYYY-MM-DD
*USA MM/DD/YYYY
*EUR MM.DD.YYYY
*MDY MM/DD/YY
*YMD YY/MM/DD
*DMY DD/MM/YY
*YYMD YYYY/MM/DD
*DMYY DD/MM/YYYY
*MDYY MM/DD/YYY
*YYMMDD Same as *YMD
*MMDDYY Same as *MDY
*DDMMYY Same as *DMY
*JDE CYYDDD   /* JD Edwards Julian date format */
Formatting Codes Description
MM Month as a two-digit value
ZM Month as a one or two digit value
YY Year as a two-digit value
YYYY Year as a four-digit value
YYY Year as a 3-digt value
ZYY Year as a 3-digit value, zero suppressed
RRRR or RRRZ Month as a Roman numeral
MMM or Mmm Month as a word, abbreviated. e.g., JAN or Jan
MMMMMMMMMM
Mmmmmmmmmm
Month as a fixed-length word. e.g JANUARY or January
MMMMMMMMMZ
Mmmmmmmmmz
Month as a variable length word.
e.g., JANUARY or January
DD Day of the month as a two-digit value
ZDD Day of the month zero suppressed
W Day of the week as a single letter.
e.g., S, M, T, W, T, F, S
WWW
Www
Day of the week as a 3-character abbreviation.
e.g., MON, Mon, TUE, Tue
WWWWWWWWWW
Wwwwwwwwww
Day of the week, fully spelled out.
e.g., MONDAY or Monday
WWWWWWWWWZ
Wwwwwwwwwz
Day of the week, fully spelled out, variable length.
e.g. MONDAY or Monday

If a leading asterisk is not specified, then the exact date format you have specified is used to do the conversion. That is '*ISO' is mapped to 'YYYY-MM-DD', where as a date format of 'YYMMDD' causes the date to be arranged in 2-digit year, month day format.

Return Value

The return value is the date as a character string in the format specified by the szFMT parameter.

Examples

      /INCLUDE XTOOLS/QCPYSRC,dates
     D dtNov           S               D   INZ(D'2004-11-01')
     D prtdate         S             20A  
 
     C                   eval      prtdate = DateToChar(dtNOV:'ZD Mmmmmmmmmz YYYY')

In this example, the ISO date November 1st, 2004 is converted to the following string and assigned to the PRTDATE field.

1 November 2004