Android Question calculate the days (not the number) as a list between 2 dates

ronnhdf

Member
Licensed User
Longtime User
Hello,

how can I display or calculate the days (not the number) as a list between 2 dates?
 

edm68

Member
Licensed User
Longtime User
Hi,
There is probably better ways, but this seems to work.
B4X:
Sub getDates
    Dim lstDates,lstDates2 As List
    lstDates.Initialize
    lstDates2.Initialize
    stripTime(startDate)
    Do While startDate+DateTime.TicksPerDay<endDate
        startDate=startDate+DateTime.TicksPerDay
        lstDates.Add(startDate)
        lstDates2.Add(DateTime.Date(startDate))
    Loop   
    For i=0 To lstDates.Size-1
        Log(lstDates.Get(i))
        Log(lstDates2.Get(i))
    Next
End Sub

Sub stripTime(Ticks As Long) As Long    'remove time
    Return DateUtils.SetDate(DateTime.GetYear(Ticks), _
        DateTime.GetMonth(Ticks),DateTime.GetDayOfMonth(Ticks))
End Sub
 
Upvote 0

ronnhdf

Member
Licensed User
Longtime User
Hi,
Thank you for your Help!
I have solved the problem like this.
B4X:
Sub cal_days(start As Long, ende As Long)
    TempDates.Clear
    Dim wert,sum,zw As Long
    Dim i As Int
    If start > ende Or start = ende Then
        Log("Fehler Datum")
        Dayslabel.Text="Fehler Datum"
    Else
    wert = ende-start
    zw = wert/1000/ 60 / 60 / 24+2
    Log(zw & " Tage")
    Dayslabel.Text=zw & " Tage"
    For i= 0 To zw-1
        sum = DateTime.Add(start,0,0,i)
        'Log(DateTime.Date(sum))
            TempDates.Add(DateTime.Date(sum))
    Next
    End If
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…