Jump to content

calendar arithmetic


Recommended Posts

You create a date() object, and then you can use a timedelta() object to operate with it. Examples are shown here: https://docs.python.org/3/library/datetime.html#datetime.date

A short program to add a number of days to a date might look like this:

d = date(2018, 7, 20)
delta = timedelta(days=5)
d2 = d + delta

There might be a shorter way to write it, but I don't work with Python very often so I'd have to look it up to make sure.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...