Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13951

Python iterate between two datetime objects [duplicate]

$
0
0

How can I iterate between two datetime.date objects in Python?

For example, if I have two dates:

date1 = datetime.date(2024, 1, 10)date2 = datetime.date(2024, 1, 20)

and I want to do something like this:

while date1 < date2:    # do something    date1 += 1 # days

How can I increment a datetime.date object by 1 day? There doesn't appear to be a way to manipulate a date object like that in Python?

https://docs.python.org/3/library/datetime.html#date-objects


Viewing all articles
Browse latest Browse all 13951

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>