Day Of Year
This algorithm finds the number of current day in a year according to the input date.
Public Shared Function DayOfYear(year As UInteger, month As Byte, day As Byte) As Integer
Dim days As UShort() = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}
If IsLeapYear(year) AndAlso month >= 2 Then
Return days(month - 1) + day + 1
End If
Return days(month - 1) + day
End Function
Private Shared Function IsLeapYear(year As UInteger) As Boolean
Return (year Mod 4 = 0 AndAlso (year Mod 100 <> 0 OrElse year Mod 400 = 0))
End Function
Example
Dim value = DayOfYear(CUInt(DateTime.Now.Year), CByte(DateTime.Now.Month), CByte(DateTime.Now.Day))
Output
271