DATECVT: Converting the Format of a Date

How to:

The DATECVT function converts the field value of any standard date format or legacy date format into a date foromat (offset from the base date), in the desired standard date format or legacy date format. If you supply an invalid format, DATECVT returns a zero or a blank.


Top of page

x
Syntax: How to Convert a Date Format
DATECVT(date, 'in_format', output)

where:

date

Date

Is the date to be converted. If you supply an invalid date, DATECVT returns zero. When the conversion is performed, a legacy date obeys any DEFCENT and YRTHRESH parameter settings supplied for that field.

in_format

Alphanumeric

Is the format of the date enclosed in single quotation marks. It is one of the following:

  • A non-legacy date format (for example, YYMD, YQ, M, DMY, JUL).
  • A legacy date format (for example, I6YMD or A8MDYY).
  • A non-date format (such as I8 or A6). A non-date format in in_format functions as an offset from the base date of a YYMD field (12/31/1900).
output

Alphanumeric

Is the output format. It is one of the following:

  • A non-legacy date format (for example, YYMD, YQ, M, DMY, JUL).
  • A legacy date format (for example, I6YMD or A8MDYY).
  • A non-date format (such as I8 or A6). This format type causes DATECVT to convert the date into a full component date and return it as a whole number in the format provided.


Example: Converting the Format of a Date

This example first converts a numeric date, NUMDATE, to a character date, and then assigns the result to a non-date alphanumeric field, CHARDATE.

CHARDATE/A13 = DATECVT (NUMDATE,'I8YYMD','A8YYMD');

Note: DATECVT does not use an output format; it uses the format of the argument output_format for the result.


iWay Software