LC0083 - StefanMaron/BusinessCentral.LinterCop GitHub Wiki

Use new Date/Time/DateTime methods for extracting parts.

Embrace the modernized Date, Time, and DateTime APIs by using the new, more intuitive methods for extracting specific parts of these types. These updated methods improve code readability and maintainability compared to the older, less descriptive alternatives.

Examples

Type New method Existing Description
Date MyDate.Day() Date2DMY(MyDate, 1) Gets the day of month from MyDate
Date MyDate.Month() Date2DMY(MyDate, 2) Gets the month from MyDate
Date MyDate.Year() Date2DMY(MyDate, 3) Gets the year from MyDate
Date MyDate.DayOfWeek() Date2DWY(MyDate, 1) Gets the day of week from MyDate
Date MyDate.WeekNo() Date2DWY(MyDate, 2) Gets the week number from MyDate
Date MyDate.Year() Date2DWY(MyDate, 3) Gets the year from MyDate
Time MyTime.Hour() Evaluate(i, Format(Time, 2, '<HOURS24>')) Gets the hours MyTime (0..23).
Time MyTime.Minute() Evaluate(i, Format(Time, 2, '<MINUTES>')) Gets the hours MyTime (0..59).
Time MyTime.Second() Evaluate(i, Format(Time, 2, '<SECONDS>')) Gets the hours MyTime (0..59).
Time MyTime.Millisecond() Evaluate(i, Format(Time, 3, '<THOUSANDS>')) Gets the hours MyTime (0..999).
DateTime MyDateTime.Date() DT2Date(MyDateTime) Gets the date part of MyDateTime
DateTime MyDateTime.Time() DT2Time(MyDateTime) Gets the time part of MyDateTime

Date2DWY(MyDate, 3) vs MyDate.Year()

MyDate.Year() is not always a direct replacement for Date2DWY(MyDate, 3). While both return the year component of a date, they behave differently.

When the input date to the Date2DWY method is in a week that spans two years, the Date2DWY method computes the output year as the year that has the most days. For example, the input date is 01/01/2014. This date is in a week that starts on Monday, December 29, 2013, and ends Sunday, January 4, 2014. The week has three days in 2013 and four days in 2014. So the output year is 2014.

System.Date2DWY(Date, Integer) Method - Business Central | Microsoft Learn

Read more