Get Days from Month in D365 BC:
(I) Create procedure or function in a object (like page, report, table and code unit).
(II) Define parameters and return value in procedure as shown below-
(III) When the above procedure or function is call then it will give total number of days in month.
(IV) If GetMonth := 3; and GetYear := 2021; then system gives 31 days.
Source Code:
codeunit 50001 “Custom Functions-01” { trigger OnRun() begin end; local procedure HowToGetDaysInMonth(GetMonth: Integer; GetYear: Integer): Integer var MODValue: Decimal; NoOfDays: Integer; begin GetMonth := 3; // Assign value to variable GetYear := 2021; // Assign value to variable NoOfDays := 0; IF GetMonth IN [1, 3, 5, 7, 8, 10, 12] THEN NoOfDays := 31; IF GetMonth IN [2] THEN BEGIN MODValue := GetYear MOD 4; IF MODValue = 0 THEN NoOfDays := 29 ELSE NoOfDays := 28; END; IF GetMonth IN [4, 6, 9, 11] THEN NoOfDays := 30; EXIT(NoOfDays); end; } |