%DATE (Convert to Date)


%DATE converts the value of the expression from character, numeric, or timestamp data to type date. The converted value remains unchanged, but is returned as a date.

The first parameter is the value to be converted. If you do not specify a value, %DATE returns the current system date.

The second parameter is the date format for character or numeric input. Regardless of the input format, the output is returned in *ISO format.

For information on the input formats that can be used, see Date Data Type. If the date format is not specified for character or numeric input, the default value is either the format specified on the DATFMT control-specification keyword or *ISO. For more information, see DATFMT(fmt{separator}).

If the first parameter is a timestamp, *DATE, or UDATE, do not specify the second parameter. The system knows the format of the input in these cases.

For more information, see Information Operations or Built-in Functions.

Figure 1. %DATE Example

   string = '040596';
   date =  %date(string:*MDY0);
   // date now contains d'1996-04-05'