ameliabob Posted July 20, 2018 Share Posted July 20, 2018 I can see functions allowing the calculations of the difference between two dates but I cannot locate how to find the addition or subtraction of x number of days from a given date. Is there such a thing in python? Link to comment Share on other sites More sharing options...
Ingolme Posted July 20, 2018 Share Posted July 20, 2018 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now