Announcements
Hi
I want to calculate the number of month between a fromDate and ToDate.
Thanks, it worked
How can we calculate days, as number of days are not fixed in year and month?
That working as it should, thanks for that ...had to adjust the code slightly to suite my scenario.
Thanks..
another suggestion just in case:
Date.Setrange("Period Type", Date."Period Type"::Month);
Date.Setfilter("Period Start", '>=%1&<=%2', StartDate, EndDate);
Message('Months between %1 and %2 is %3', StartDate, EndDate, Date.Count - 1);
Variable >> Date: Record Date
Hi,
How would you change your sample calculation to suite a service date - next service date = No. of days bitween.
but i need another coloum to show the current no.of days left till next service.
hope it makes sence.
I did it this way:
Clear(NoOfMonths); NoOfMonths := DATE2DMY("Shipment Date", 2) - DATE2DMY(TODAY, 2) 12 * (DATE2DMY("Shipment Date", 3) - DATE2DMY(TODAY, 3));
But ZHU's answer is also correct.
Hi, as Josh Anglesea said, you should pay attention to different years.
A simple example: for reference only
pageextension 50100 MyExtension extends "Customer List" { trigger OnOpenPage() begin Message('Months between %1 and %2 is %3', 20150101D, Today, CalculateMonthBetweenTwoDate(20150101D, Today)); end; local procedure CalculateMonthBetweenTwoDate(StartDate: Date; EndDate: Date): Integer var NoOfYears: Integer; NoOfMonths: Integer; begin NoOfYears := DATE2DMY(EndDate, 3) - DATE2DMY(StartDate, 3); NoOfMonths := DATE2DMY(EndDate, 2) - DATE2DMY(StartDate, 2); exit(12 * NoOfYears NoOfMonths); end; }
Hope this will help.
Thanks.
ZHU
Does that assume it’s the same year?
Use Date2DMY to get the both month for comparison.
fromMonth := Date2DMY(fromDate,2);
toMonth := Date2DMY(toDate,2);
Diff := toMonth - fromMonth;
André Arnaud de Cal...
293,309
Super User 2025 Season 1
Martin Dráb
232,160
Most Valuable Professional
nmaenpaa
101,156
Moderator