Tuesday, July 8, 2008

Date Operation

Date and Time Operation in RPGLE:
*ISO format is the default format, for all Date, Time and Timestamp.
There are various formats available for Date and Time. There are as follows.

Length ->8
*MDY mm/dd/yy
*DMY dd/mm/yy
*YMD yy/mm/dd
*JUL yy/days

*LOVAL=1940
*HIVAL=2039

Length ->10
*EUR dd.mm.yyyy
*USA mm/dd/yyyy
*ISO yyyy-mm-dd
*JIS yyyy-mm-dd


*LOVAL=0001
*HIVAL=9999

*CMDY cmm/dd/yy
*CDMY cdd/mm/yy
*CYMD cyy/mm/dd
*LONGJUL

C=0 1900-1999
C=1 2000-2099
C=2 2100-2199

TIME

*HMS hh:mm:ss

*ISO hh.mm.ss

*USA hh:mm(AM/PM)

*JIS hh:mm:ss

*EUR hh.mm.ss


Timestamp:
*ISO-> yyyy-mm-dd-hh.mm.ss.mmmmmm =>length is 26.

H-Spec Declaration:

If we specify DATFMT in H-spec with particular format, then whole project would follow in the same format, as mentioned above.

e.g. For declaring date field inside the RPGLE program.

D Datefield S D INZ(D’21 07 99’)

If it is Date then it should have ‘D’ infront. If it is Time then we should have ‘T’ infront. If it is Timestamp then we can have ‘Z’.

In Free Format:

%date(expression{:Date-format})

While declaring Date,Time and Timestamp inside the program in the D-specification, Dataformats can be ‘D’,’T’,’Z’ respectively.

e.g.

D loandate S D
D Curtime S T
D Timest S Z

e.g. For Built in Functions is

D str S 8A Inz(‘20080630’)
D date1 S D
/free
date1=%date(str:*ISO0)
/end-free


*ISO0
0-> No separator or else we have to specify which parameter we have to use in the program.

Built-in Functions DurationCodes

%years *Years or *Y
%months *Months or *M
%days *Days or *D
%hours *Hours or *H
%Minutes *Mintues or *MN
%Seconds *Seconds or *S
%Mseconds *Mseconds or *MS


Operation with Date:

Subset of a Date:

SUBST

Built in Functions : %Subst(value:*durationcodes)


EXTRCT:
e.g. and Usage exactly

C EXTRCT Date1:*D Days

Date1: 2006-08-24
Days: 24

DIFF


Built in functions:

Var=%Diff(op1:op2:*m)

Op1=2008-07-30
Op2=2008-05-23

Var=2

MOVE
We can move the string to Date/Time/Timestamp or from Date/Time/Timestamp to String also.

e.g.

C MOVE Date1 nudate2
C *MDY0 MOVE Date1 stdate2

ADDDUR:
It is used to Add duration of period or time or timestamp. It usage is as follows.

C Loandate ADDDUR 18:*Years Loandate1

Loandate = 2008-06-10
Loandate1= 2026-06-10

SUBDUR
It is used to subtract the period or Time or timestamp.

C Date/time SUBDUR Date/time var1:*m

TEST:
Test opcodes are used to check whether the given factor1 is exactly equal to factor2. If not LOW level indicator will be on.

TEST(D)
TEST(T)
TEST(Z)


e.g.

C Datfmt TEST(D) char/num ER
C Timfmt TEST(D) char/num ER
C Timstmp TEST(D) char/num ER


CONVERSION OF DATE IN CLP PROGRAM :

CVTDAT DATE(&OLDDATE) TOVAR(&NEWDATE)
FROMFMT(*DMY) TOFMT(o*USA) TOSEP(/)