Fri Nov 26, 2021 11:00 pm
Login Register Lost Password? Contact Us


Last date of the given month and year

Comments and questions related to the Enterprise Control Language

Thu Jul 08, 2021 12:55 pm Change Time Zone

Team,

I am finding it hard to calculate the last date for the given month and year. I searched Date library and couldn't figured it out from there. For instance if the input is year - 2015 and month - 12 the output should be 31.

Is the only way to write UDF with hardcoded last date monthg values considering the leap year or any other ways within date lib ?
ravishankar
 
Posts: 17
Joined: Wed Mar 18, 2015 5:24 am

Thu Jul 08, 2021 1:38 pm Change Time Zone

ravishankar,

You can get the Days_t value for the first day of the next month and subtract 1, then translate that back to a Date value. Something like this:
Code: Select all
IMPORT STD;
D := STD.Date.FromGregorianYMD(2015,12 + 1,1) - 1;
X := STD.Date.ToGregorianYMD(D);
X.Day; //returns 31
Note that you just add one to the month you want and the FromGregorianYMD() function correctly handles month 13.

HTH,

Richard
rtaylor
Community Advisory Board Member
Community Advisory Board Member
 
Posts: 1604
Joined: Wed Oct 26, 2011 7:40 pm

Thu Jul 08, 2021 2:05 pm Change Time Zone

Thanks a lot Richard , this helps.
ravishankar
 
Posts: 17
Joined: Wed Mar 18, 2015 5:24 am


Return to ECL

Who is online

Users browsing this forum: No registered users and 1 guest

cron