4
I’m having trouble generating an iteration where dates are displayed from a given day to the most current day. this problem happens when it has the "turn of the year" and I put a condition of "stop".
Code with wrong return:
df0 = pd.DataFrame({"datasolicitada":['21/12/2020 00:00','18/12/2020 00:00']})
data = df0['datasolicitada'].max()
data1 = datetime.strptime(data, "%d/%m/%Y %H:%M")
data2 = data1.strftime("%d/%m/%Y")
datahj = datetime.today().strftime("%d/%m/%Y")
for i in range(30):
dia = (data1 + timedelta(days=i)).strftime("%d/%m/%Y")
if datahj > dia:
print (dia)
If I run only the print
of the count, it is returned to me until the sum according to the range
for i in range(30):
dia = (data1 + timedelta(days=i)).strftime("%d/%m/%Y")
print (dia)
Results:
if datahj > dia:
print (dia)
01/01/2021
02/01/2021
03/01/2021
04/01/2021
05/01/2021
if I change the sign of the condition:
if datahj < dia:
print (dia)
21/12/2020
22/12/2020
23/12/2020
24/12/2020
25/12/2020
26/12/2020
27/12/2020
28/12/2020
29/12/2020
30/12/2020
31/12/2020
07/01/2021
08/01/2021
09/01/2021
10/01/2021
11/01/2021
12/01/2021
13/01/2021
14/01/2021
15/01/2021
16/01/2021
17/01/2021
18/01/2021
19/01/2021
result you would like to have:
21/12/2020
22/12/2020
23/12/2020
24/12/2020
25/12/2020
26/12/2020
27/12/2020
28/12/2020
29/12/2020
30/12/2020
31/12/2020
01/01/2021
02/01/2021
03/01/2021
04/01/2021
05/01/2021
thank you very much for the explanation, I will read more about, hug
– Saulo