Date, time or timestamp expression

When the first parameter is a date time or timestamp expression, the optional format parameter specifies the format of the value returned. The converted decimal value will have the number of digits that a value of that format can have, and zero decimal positions. For example, if the first parameter is a date, and the format is *YMD, the decimal value will have six digits. If the first parameter is a timestamp with three fractional seconds, the decimal value will have 17 digits.

If the format parameter is omitted, the format of the first parameter is used. See DATFMT(fmt{separator}) and TIMFMT(fmt{separator}).

Format *USA is not allowed with a time expression. If the first parameter is a time value with a time-format of *USA, the second format parameter for %DEC must be specified.

Figure 1 shows an example of the %DEC built-in function.

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

Using %DEC to convert dates, times and timestamps to numeric

The examples use the following definitions.

   DCL-S yyddd ZONED(5);
   DCL-S yyyymmdd PACKED(8);
   DCL-S hhmmss PACKED(6);
   DCL-S numeric ZONED(20);
   DCL-S date DATE(*USA) INZ(D'2003-06-27');
   DCL-S time TIME INZ(T'09.25.59');
   DCL-S timestamp TIMESTAMP INZ(Z'2003-06-27-09.25.59.123456');
   DCL-S timestamp3 TIMESTAMP(3) INZ(Z'2003-06-27-09.25.59.123');
  • Using the format of the first parameter:
    
       numeric = %dec(date);             //   numeric = 06272003
       numeric = %dec(time);             //   numeric = 092559
       numeric = %dec(timestamp);        //   numeric = 20030627092559123456
       numeric = %dec(timestamp3);       //   numeric = 20030627092559123
    
  • Using the second parameter to specify the result format:
    
       yyddd = %dec(date : *jul);        //   yyddd = 03178
       yyyymmdd = %dec(date : *iso);     //   yyyymmdd = 20030627
    
  • Using the *LONGJOBRUN format to use the date format with 4-digit years that is related to the job date format. In this example, the job date format is *DMY, so the *LONGJOBRUN format is the same as the *EUR format.
    
       numeric = %dec(date : *longjobrun);// numeric = 27062003