Page 1 of 1

Date Validation

Posted: July 6th, 2022, 4:45 am
by rksraajput
Hi CSpro Team,
I am preparing a CAPI, in this I have to validate the date of joining the organization with regard to organization formation date and the current date. I have separate items in dictionary for month and year in all (for current, joining and formation).
I want to check (organization formation date < date of joining < current date)
Thank

Re: Date Validation

Posted: July 6th, 2022, 7:29 am
by Gregory Martin
Take a look at the cmcode function: https://www.csprousers.org/help/CSPro/c ... ction.html

That will give you a number that combines the year and month, and you can use that number to compare dates.

Re: Date Validation

Posted: July 6th, 2022, 1:24 pm
by rksraajput
Thanks for the response!!!


F_YEARS = Formation Year
F_MONTH = Formation Month
Q301_Y = Year of Joining
Q301_M = Month of joining
I tried it like this but it didn't work
if cmcode (F_YEARS , F_MONTH) < cmcode (Q301_Y, Q301_M) then
errmsg (" XXXXXXXXXX ");
reenter;
endif;
before I was using like this
if Q301_M < F_MONTH then
if Q301_Y < F_YEARS then
errmsg (" XXXXXXXXXXX ");
reenter;
endif;
endif;

but it doesn't validate with current date

Thank You

Re: Date Validation

Posted: July 7th, 2022, 10:40 am
by Gregory Martin
Take a look at cmcode's parameters: the month comes first, then the year:
if cmcode(F_YEARS, F_MONTH) < cmcode(Q301_Y, Q301_M) then // WRONG

if cmcode(F_MONTH, F_YEARS) < cmcode(Q301_M, Q301_Y) then // CORRECT
You can get the current date with:
cmcode(sysdate("MM"), sysdate("YYYY"))

Re: Date Validation

Posted: July 7th, 2022, 11:59 am
by rksraajput
Thanks a lot!
it worked