Date Validation

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
Post Reply
rksraajput
Posts: 8
Joined: May 24th, 2022, 3:29 pm

Date Validation

Post 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
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Date Validation

Post 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.
rksraajput
Posts: 8
Joined: May 24th, 2022, 3:29 pm

Re: Date Validation

Post 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
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Date Validation

Post 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"))
rksraajput
Posts: 8
Joined: May 24th, 2022, 3:29 pm

Re: Date Validation

Post by rksraajput »

Thanks a lot!
it worked
Post Reply