user3782816
user3782816

Reputation: 171

Incrementing a date in python

In pandas I have a variable defined as

start_date = date (2020,7,1)

How do I update it to be the next day? I have a dataframe and I am filtering on individual days but I want to iterate through a full time range. I suppose I could have a for loop like so

for x < 10:
    start_date = date (2020,7,x)
    x +=1

But is there another way? I couldn't find any other stack exchange questions for python dates.

Upvotes: 0

Views: 60

Answers (1)

Tim Tisdall
Tim Tisdall

Reputation: 10382

Assuming date is the regular python one you can add a day as follows:

from datetime import date, timedelta

start_date = date(2020, 7, 1)
next_date = start_date + timedelta(days=1)

Upvotes: 1

Related Questions