Thu Jul 07, 2022 7:27 am
Login Register Lost Password? Contact Us

Please Note: The HPCC Systems forums are moving to Stack Overflow. We invite you to post your questions on Stack Overflow utilizing the tag hpcc-ecl ( This legacy forum will be active and monitored during our transition to Stack Overflow but will become read only beginning September 1, 2022.

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


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 ?
Posts: 17
Joined: Wed Mar 18, 2015 5:24 am

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


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
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.


Community Advisory Board Member
Community Advisory Board Member
Posts: 1619
Joined: Wed Oct 26, 2011 7:40 pm

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

Thanks a lot Richard , this helps.
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