This code calculates the first and last date of the previous month.
1 2 3 4 5 6 7 8 9 10 11 12 | static void EP_dateMonthInterval(Args _args) { date fromDate; date toDate; date baseDate = systemDateGet(); ; toDate = dateStartMth(baseDate) - 1; fromDate = dateStartMth(toDate); info(strFmt("%1 - %2", fromDate, toDate)); } |
UtcDateTime version of the same job.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | static void EP_UtcdateMonthInterval(Args _args) { UtcDateTime fromDate; UtcDateTime toDate; UtcDateTime baseDate = DateTimeUtil::utcNow(); ; // Remove this month number of days. toDate = DateTimeUtil::addDays( baseDate, -(DateTimeUtil::day(baseDate) -1)); // Add the rest of this days time minus one second. toDate = DateTimeUtil::addSeconds( toDate, -(DateTimeUtil::time(toDate)+1)); // Remove the number of days we are on in // the previous month and add one second to // get to the first of the month. fromDate = DateTimeUtil::addSeconds( DateTimeUtil::addDays( toDate, -(DateTimeUtil::day(toDate))), 1); info(strFmt("%1 - %2", fromDate, toDate)); } |
Last 5 posts in Dynamics AX
- How to call a web API from Dynamics 365 FO X++ - December 1st, 2020
- Cannot add or remove static keyword for this method - May 30th, 2016
- Sales line number not unique - May 27th, 2016
- DMF - DMF Service is unavailable - November 7th, 2012
- DMF - Error occured while doing bulkcopy from temp table to entity table - November 6th, 2012