IBMi (AS400) fans only : %DIFF BIF - How to add or subtract days from a date field %days(n)
#IBMiSample
We can use %DAYS to add or subtract to a date.
Hier is an example:
TESTDY.DSPF
A DSPSIZ(*DS3)
A CHGINPDFT(UL CS)
A PRINT
A CF03(03)
A*******************************************************
A* F01 *
*******************************************************
A R F01
A OVERLAY
A 1 31'PARAMETERS REQUEST'
A DSPATR(HI)
*
A 3 8'Insert a date (yymmdd):'
A PPDT00DMY 6Y 0B + 1EDTCDE(Y)
A PPDT0RYMD 6Y 0O +4EDTCDE(Y)
A 4 8'Insert a date (ddmmyy):'
A PPDT10DMY 6Y 0B + 1EDTCDE(Y)
A PPDT1RYMD 6Y 0O +4EDTCDE(Y)
A 5 8'Insert a date *ISO (ccyymmdd):'
A PPDTISO L B + 1
A PPDT2RCYMD L O +2
A 6 8'Insert a date *EUR (ddmmyycc):'
A PPDTEUR L B + 1DATFMT(*EUR)
A PPDT3RCYMD L O +2
A 7 8'Insert a displacement :'
A PPDSPL 3Y 0B + 1EDTCDE(K)
*******************************************************
* P00 *
*******************************************************
A R P00
A 24 3'F3=EXIT'
TESTDY.RPGLE
**free
*************************************************************************
* Exampel %days *
*************************************************************************
ctl-opt DFTACTGRP(*NO);
*
dcl-f TESTDYFM workstn;
*
dcl-s PPDT00YMD zoned(6);
dcl-s PPDT10YMD zoned(6);
dcl-s PPEXIT char(1);
*
// *********************************************************************
// PGM start
// *********************************************************************
PPEXIT = 'N';
dow (1 = 1) ;
write p00;
exfmt f01;
if (*in03);
PPEXIT = 'Y';
leave;
endif;
if (*in03 = *off);
PPDT0RYMD = %dec(%char(%date(PPDT00DMY:*ymd) +
%Days(PPDSPL) :*ymd0):6:0); // from yymmdd to yymmdd
PPDT10YMD = %dec(%date(PPDT10DMY:*ymd):*dmy); // ddmmyy to yymmdd
PPDT1RYMD = %dec(%char(%date(PPDT10YMD:*ymd) +
%Days(PPDSPL) :*ymd0):6:0); // from yymmdd to yymmdd
PPDT2RCYMD = PPDTISO + %Days(PPDSPL); // from ccyymmdd to ccyymmdd
PPDT3RCYMD = PPDTEUR + %Days(PPDSPL); // from ccyymmdd to ccyymmdd
endif;
enddo;
*inlr = *on;
I appreciate all the comments made on this blog.
What about adddur and subdue
ReplyDelete