CL SysDate Conversion

pts.
Tags:
CL
CL programming
CL SysDate Conversion
Hi I have converted the sys date to *CYMD format.I have two problems, 1.For eg 19/12/08 is now 1081219,where 1 stands for 2000-2050 and 0 stands for 1900 to 1999(defined in system).But i want to map this with dates in file whose format is 20081219. 2.If this is possible i need to subtract the date by 1 and then move to a dataarea.All done using CL. Please suggest.

Answer Wiki

Thanks. We'll let you know when a new response is added.

Hi,

Try adding 19000000 (6 x zeros) to your *CYMD date.

Regards,

Martin Gilbert.

Discuss This Question: 9  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Sorry i didnt get you...can you please explain
    0 pointsBadges:
    report
  • philpl1jb
    That was an old RPG trick. This is a CL requirement -- check out the command CVTDAT If you have TATOOL look at ADDDAT or ADDDAT2
    49,550 pointsBadges:
    report
  • I have coverted to *cymd format.But sinde this is *char i will not be able to subtract from this.Can this be done only using julien...is there a way to subtract form the curren date
    0 pointsBadges:
    report
  • philpl1jb
    If you don't have TATOOLs with the ADDDAT command then yes 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.
    49,550 pointsBadges:
    report
  • Thanks for the info...Is there a simpler process this one seems too elaborate...if not then i will proceed with ur suggestion.I dont have taatoll to use ADDDAT but if there are similar opcodes it could help
    0 pointsBadges:
    report
  • hI 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
    0 pointsBadges:
    report
  • philpl1jb
    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 &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
    49,550 pointsBadges:
    report
  • Hey 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...
    0 pointsBadges:
    report
  • philpl1jb
    No, of course not -- that would be too easy but I think this will work 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
    49,550 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following