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 new 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 the Format of a Date
DATECVT(date, in_format, output_format)

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, either standard, legacy, or non-date.

For example:

  • A standard, 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 in the in_format argument causes DATECVT to interpret the whole number in the date field as a full component date.
output_format

Alphanumeric

Is the output date format, either standard, legacy, or non-date.

For example:

  • A standard, 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 in output_format argument 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