Android Code Snippet [B4X] Get number of days in year

B4X:
Public Sub GetNumberOfDaysInYear(Year As Int) As Int
    Return DateUtils.PeriodBetweenInDays(DateUtils.SetDate(Year,1,1),DateUtils.SetDate(Year,12,DateUtils.NumberOfDaysInMonth(12,Year))).Days +1
End Sub
or
B4X:
Public Sub GetNumberOfDaysInYear2(Year As Int) As Int
    Return DateTime.GetDayOfYear(DateUtils.SetDate(Year,12,31))
End Sub
or
from @mcqueccu
B4X:
Public Sub GetNumberOfDaysInYear3(Year As Int) As Int
    DateTime.DateFormat = "yyyy/MM/dd"
    Dim d As Long = DateTime.DateParse($"${Year}/12/31"$)
    Return DateTime.GetDayOfYear(d)
End Sub
or
from @epiCode
B4X:
Sub GetDaysInYear(year As Int) As Int
    Return IIf((year Mod 4 = 0 And year Mod 100 <> 0) Or year Mod 400 = 0, 366, 365)
End Sub
 
Last edited:

Alexander Stolte

Expert
Licensed User
Longtime User
or
B4X:
Public Sub GetNumberOfDaysInYear2(Year As Int) As Int
    Return DateTime.GetDayOfYear(DateUtils.SetDate(Year,12,31))
End Sub

anyways, i put all 3 in the first post
 

Theera

Well-Known Member
Licensed User
Longtime User
Let me include your class in B4xstringfunctionVB. Let me include your class in B4xstringfunctionVB.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…