As the title suggests, I will like to get a full date from a day number out of ~365 days in the year.
For example, when I enter day 171, it should get 2022-06-20
DateUtils is a code module with a set of useful date and time related methods. It complements DateTime api, it doesn't replace it. The methods included in DateUtils: 'Calculates the period between two date instances. 'This method returns a Period type with years, months, days, hours, minutes...
DateUtils is a code module with a set of useful date and time related methods. It complements DateTime api, it doesn't replace it. The methods included in DateUtils: 'Calculates the period between two date instances. 'This method returns a Period type with years, months, days, hours, minutes...
Sub getDateFromDayNumber (day As Int) As String
DateTime.DateFormat = "yyyy/MM/dd"
Dim yr As Int = DateTime.GetYear(DateTime.Now)
Dim p As Period
p.Days = day - 1
Dim nDate As Long = DateUtils.AddPeriod(DateTime.DateParse($"${yr}/01/01"$),p)
Return DateTime.Date(nDate)
End Sub
Here is another Variation that does not depend on DateUtils
B4X:
Sub getDateFromDayNumber2 (day As Int) As String
DateTime.DateFormat = "yyyy/MM/dd"
Dim yr As Int = DateTime.GetYear(DateTime.Now)
Dim d As String = $"${yr}/01/01"$
Dim nDate As Long = DateTime.Add(DateTime.DateParse(d),0,0,day - 1)
Return DateTime.Date(nDate)
End Sub