ProblemYou want to calculate the day of the year for a date, a number in the range 1 to 366. SolutionUse the Date object's DayOfYear property to get this number directly, with no calculations required. DiscussionThe following code shows how to determine a date's day of the year: Dim rightNow As Date = Now Dim yearDay As Integer = rightNow.DayOfYear Dim results As String = String.Format( _ "Day of year for {0:D}: {1}", Now, yearDay) MsgBox(results) Figure 7-16 shows the day of the year for a date, as displayed by the message box in the sample code. Figure 7-16. Determining the day of year for a specific date with the Date object's DayOfYear property |