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 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 204 shows an example of the %DEC built-in function.
For more information, see Conversion Operations or Built-in Functions.
D yyddd S 5S 0
D yyyymmdd S 8P 0
D hhmmss S 6P 0
D numeric S 20S 0
D date S D inz(D'2003-06-27') DATFMT(*USA)
D time S T inz(T'09.25.59')
D timestamp S Z inz(Z'2003-06-27-09.25.59.123456'
/free
// Using the format of the first parameter
numeric = %dec(date); // numeric = 06272003
numeric = %dec(time); // numeric = 092559
numeric = %dec(timestamp); // numeric = 20030627092559123456
// Using the second parameter to specify the result format
yyddd = %dec(date : *jul); // yyddd = 03178
yyyymmdd = %dec(date : *iso); // yyyymmdd = 20030627