since &FCT has zero decimals dividing by 4 would loose the fractional part

then multiply by 4 and compare with the original. If they are the same it’s a leap

year — unless it isn’t — see below!

dcl &FCT *dec 2 0

chgvar &FCT (&YYd/4)

chgvar &FCT (&FCT * 4)

if (&FCT = &YYd)

The year 2000 is a leap year. Some programs know about

this. They simply check whether a year is divisible

by 4, and hence conclude that 2000 is a leap year.

Or they are more rigorous and are aware of the exception:

a year that is divisible by 100 as well is

not a leap year, unless it is also divisible by 400. In

other words, neither 1900 nor 2100 are leap years,

but 2000 is.

So this code is good till 2100

Phil

Thanks a lot…I was finally able to get it done with quite a bit of coding…one last question regarding this …is there an opcode to check the factor of a number…can you explain how to build that condition…

]]>DCL VAR(&CURDT) TYPE(*CHAR) LEN(6)

DCL VAR(&YYDDD) TYPE(*CHAR) LEN(5)

DCL VAR(&JULIAN) TYPE(*DEC) LEN(5 0)

RTVSYSVAL SYSVAL(QDATE) RTNVAR(&CURDT)

CVTDAT DATE(&CURDT) TOVAR(&YYDDD) FROMFMT(*SYSVAL) +

TOFMT(*JUL) TOSEP(*NONE)

CHGVAR &DDDc substr(&Julian 3 5)

CHGVAR &YYC substr(&Julian 1 2)

CHGVar &DDDd &DDDc

ChgVar &YYd &YYc

CHGVar &DDDd (&DDDd-1)

if (&DDDd = 0) then do

chgvar &YYd (&YYd -1)

chgvar &DDDd 365 <<– right in here you would need to determine

if the new &YYd was a factor or 4

EndDo

CHGVAR VAR(&JULIAN) VALUE(&YYDDD)

CHGVAR VAR(&JULIAN) VALUE(&JULIAN-1)

CHGVAR VAR(&YYDDD) VALUE(&JULIAN)

CVTDAT DATE(&YYDDD) TOVAR(&DATE) FROMFMT(*JUL) +

TOFMT(*SYSVAL) TOSEP(*NONE)

SNDPGMMSG MSG(&CURDT)

ENDPGM

i used the below code to get a day before current date.But this will not work on jan 1st and i have not handled for a leap year.

Can you please suggest..

PGM

DCL VAR(&CURDT) TYPE(*CHAR) LEN(6)

DCL VAR(&YYDDD) TYPE(*CHAR) LEN(5)

DCL VAR(&JULIAN) TYPE(*DEC) LEN(5 0)

RTVSYSVAL SYSVAL(QDATE) RTNVAR(&CURDT)

CVTDAT DATE(&CURDT) TOVAR(&YYDDD) FROMFMT(*SYSVAL) +

TOFMT(*JUL) TOSEP(*NONE)

CHGVAR VAR(&JULIAN) VALUE(&YYDDD)

CHGVAR VAR(&JULIAN) VALUE(&JULIAN-1)

CHGVAR VAR(&YYDDD) VALUE(&JULIAN)

CVTDAT DATE(&YYDDD) TOVAR(&DATE) FROMFMT(*JUL) +

TOFMT(*SYSVAL) TOSEP(*NONE)

SNDPGMMSG MSG(&CURDT)

ENDPGM

convert to Julian, subtract 1 from the day part, if day part is 0 then subtract one from the year part

and put the day part at 365 or 366 on leap year and convert to your desired date format.

CL converts from *dec to *char and back in the CHGVAR command. So you will need to

put the last three char of the julian into a *dec 3 variable using substring.

This is a CL requirement — check out the command CVTDAT

If you have TATOOL look at ADDDAT or ADDDAT2 ]]>