Use built-in date/time methods (LC0083)
Business Central provides built-in methods for common date and time operations. Use these methods instead of manually calculating dates or times, as they handle edge cases like leap years and month boundaries correctly.
A code fix is available for this diagnostic.
Example
The following code manually calculates the first day of the month:
codeunit 50100 MyCodeunit
{
procedure GetFirstDayOfMonth(InputDate: Date): Date
begin
exit(DMY2Date(1, Date2DMY(InputDate, 2), Date2DMY(InputDate, 3))); // Use built-in date/time methods [LC0083]
end;
}
To fix this, use the built-in method:
codeunit 50100 MyCodeunit
{
procedure GetFirstDayOfMonth(InputDate: Date): Date
begin
exit(CalcDate('<-CM>', InputDate));
end;
}