Notifications
Announcements
No record found.
Dear All,
I want to get list of month + year between two dates and save in array,
and also how to to use array for date in x++
how to do this please help me
*This post is locked for comments
Dear azam,
The following is the code to get list of months between two dates, reply whether your requirements are satisfied or not.
static void Job21(Args _args)
{
str dateMonth[];
TransDate date1, date2;
int month1, month2, counter, i, cnt, y;
;
date1 = mkDate(1, 1, 2016);
date2 = mkDate(31, 11, 2016);
month1 = mthOfYr(date1);
month2 = mthOfYr(date2);
y = year(date1);
if(month2 > month1)
counter = month2 - month1;
else
counter = month1 - month2;
cnt = counter;
info(strFmt("%1 is year", y));
for( i = 1; i <=counter; i++)
dateMonth[i] = mthName(cnt);
info(strFmt("%1", dateMonth[i]));
cnt--;
}
Thanks and regards
Kamesh K
Above given job is not taking care of year.. Put the two dates in two different years and you will see results. You may try with following job.
static void YearMonthCombinations(Args _args) { //<variables for dialog and dates> Dialog dialog; DialogField dfFromDate,dfToDate; FromDate vFromDate; ToDate vToDate; date nextDate; //</variables for dialog and dates> //<variables for array> date DemoArray[]; int counterIndex; int outputCounter; //</variables for array> ; dialog = new Dialog("Year-Month Combinations"); dfFromDate = dialog.addField(extendedTypeStr(FromDate)); dfToDate = dialog.addField(extendedTypeStr(ToDate)); if(dialog.run()) { vFromDate = dfFromDate.value(); vToDate = dfToDate.value(); counterIndex = 1; nextDate = vFromDate; info(strFmt('Date: %1 Year:%2 Month%2',nextDate,year(nextDate),mthName(mthOfYr(nextDate)))); do { nextDate = dateMthFwd(nextDate,1); if(nextDate <= vToDate) { //info(strFmt('%1',nextDate)); //add value in array DemoArray[counterIndex] = nextDate; counterIndex++; } } while(nextDate <= vToDate); for(outputCounter=1; outputCounter<=counterIndex-1; outputCounter++) { info(strFmt('Date: %1 Year:%2 Month:%2',DemoArray[outputCounter],year(DemoArray[outputCounter]),mthName(mthOfYr(DemoArray[outputCounter])))); } } }
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Martin Dráb 4 Most Valuable Professional
Priya_K 4
MyDynamicsNAV 2