Hi,
I`m trying to generate a list of dates for the last days of the month, to use in a query for grouping data by month (based on a long field). I tried this but its not giving the expected result:
I`m getting this:
tmp = 01/01/2023
dt(1) = 31/01/2022
tmp = 01/02/2023
dt(2) = 31/02/2022
tmp = 01/03/2023
dt(3) = 31/03/2022
tmp = 01/04/2023
dt(4) = 31/04/2022
tmp = 01/05/2023
dt(5) = 31/05/2022
tmp = 01/06/2023
dt(6) = 31/06/2022
tmp = 01/07/2023
dt(7) = 31/07/2022
tmp = 01/08/2023
dt(8) = 31/08/2022
tmp = 01/09/2023
dt(9) = 31/09/2022
tmp = 01/10/2023
dt(10) = 31/10/2022
tmp = 01/11/2023
dt(11) = 31/11/2022
tmp = 01/12/2023
When I`m expecting dt(x) to be 31/12/2022, 31/01/2023, 28/02/2023...etc
I`m trying to generate a list of dates for the last days of the month, to use in a query for grouping data by month (based on a long field). I tried this but its not giving the expected result:
B4X:
Sub build_dates
Dim dt(12) As Long
Dim tmp As Long
Dim p1 As Period
p1.Days = -1
DateTime.DateFormat = "dd/mm/yyyy"
For i = 1 To 12
If sf.Len(i) = 1 Then
tmp = DateTime.DateParse("01/0" & i & "/" & DateTime.GetYear(DateTime.Now))
Log("tmp = " & DateTime.Date(tmp))
dt(i) = DateUtils.AddPeriod(tmp, p1)
Log("dt(i) = " & DateTime.Date(dt(i)))
Else
tmp = DateTime.DateParse("01/" & i & "/" & DateTime.GetYear(DateTime.Now))
Log("tmp = " & DateTime.Date(tmp))
dt(i) = DateUtils.AddPeriod(tmp, p1)
Log("dt(i) = " & DateTime.Date(dt(i)))
End If
Next
End Sub
I`m getting this:
tmp = 01/01/2023
dt(1) = 31/01/2022
tmp = 01/02/2023
dt(2) = 31/02/2022
tmp = 01/03/2023
dt(3) = 31/03/2022
tmp = 01/04/2023
dt(4) = 31/04/2022
tmp = 01/05/2023
dt(5) = 31/05/2022
tmp = 01/06/2023
dt(6) = 31/06/2022
tmp = 01/07/2023
dt(7) = 31/07/2022
tmp = 01/08/2023
dt(8) = 31/08/2022
tmp = 01/09/2023
dt(9) = 31/09/2022
tmp = 01/10/2023
dt(10) = 31/10/2022
tmp = 01/11/2023
dt(11) = 31/11/2022
tmp = 01/12/2023
When I`m expecting dt(x) to be 31/12/2022, 31/01/2023, 28/02/2023...etc