Announcements
No record found.
This a SQL Script, it helps me get the months between two dates, how can i achieve the same in AL Development (D365 Business Central)
datediff(month,'Specified Date',getdate())
In AL, numdays := Date1 - Date2;
Hi Dickson,
Well, to get the difference in months between two dates I suggest you to create this function:
Procedure getDatesDiffInMonths(firstDate : Date; secondDate : Date) monthsDiff : Integer begin monthsDiff := ABS(12 * (DATE2DMY(firstDate, 3) - DATE2DMY(secondDate, 3)) + DATE2DMY(firstDate, 2) - DATE2DMY(secondDate, 2)); end;
then you call it in your code :
diffInMonths := getDatesDiffInMonths(TodayDate, AnotherPastDate);
Note that DATE2DMY(firstDate, 3) returns the Year and DATE2DMY(firstDate, 2) returns the Month of the date in parameter (firstDate).
--
Don't hesitate If you need more details or explanations.
-------------
Please verify my answer if you find my answer helpful. Doing so you'll show other community members that there was found a solution and you credit my help.
Best Regards,
Thank you.
It worked.
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.
Congratulations to a top community star!
In our never-ending quest to help the Dynamics 365 Community members get answers faster …
Welcome to the next edition of the Community Platform Update. This is a status …
Stay up to date on forum activity by subscribing.