I'm trying to convert from "day of the year" to a date. For example if the day of the year is 221 the date would be August 10, 2022 (or 08/10/2022 in mm/dd/yyyy format). I came up with the following sub to do this. It works, but is extremely slow to a point where if it is called multiple times very quickly, it crashes at the "DateParse" function.
Does anyone have a better and/or more elegant suggestion on how to do this? Without using DateParse() if possible?
Does anyone have a better and/or more elegant suggestion on how to do this? Without using DateParse() if possible?
B4X:
Sub GetDate (days As Long) As String
Dim tmp As String
Dim Tics As Long
tmp="01/01/" & DateTime.GetYear(DateTime.Now) ' Jan 1 of this year
Tics = DateTime.DateParse(tmp) ' Ticks to beginning of this year
Tics = Tics + (days * 86400000) ' Add tics to days in msec
Return(DateTime.Date(Tics))
End Sub
Last edited: