Sign in

docs RPG Reference

%DATE (Convert to Date)

%DATE (Convert to Date)

%DATE{(expression{:date-format})}

%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 format is *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.

%DATE Examples

  • In the following example, the date value in the string is known to be in *USA format with no separators.

    string = '04052024';
    date =  %date(string : *USA0);
    // date = D'2024-04-05'
  • In the following example, the value in the numeric variable is known to be in the job date format, but with 4 digits for the year. In this exapmle, the job date format is *DMY and the job date separator is the slash character. Date format *LONGJOBRUN is used, so the operands are assumed to be in the *EUR format, which is the format with 4-digit years related to the *DMY format.

    1. The string contains separators. They must be the same as the job date separator.
    2. The string does not contain separators, so ‘0’ is used as the separator for the *LONGJOBRUN format.
    num = 05042024;
    date =  %date(num : *LONGJOBRUN);
    // date = D'2024-04-05'
    
    string = '07/04/2024';
    date =  %date(string : *LONGJOBRUN); //  1 
    // date = D'2024-04-07'
    
    string = '06042024';
    date =  %date(string : *LONGJOBRUN0); //  2 
    // date = D'2024-04-06'