2

I came up with some ideas how to add 30 days. But code should add 31 days if this month has 31 days or 28 , for example, if it is Febuary. The only library that should be used is datetime. This is what i came with.

 def get_next_month(date):
   month = (date.month % 12) + 1
   year = date.year + (date.month + 1 > 12)
   datetime.datetime(year, month, 1)

But it's not completely correct(

Alex Nikitin
  • 841
  • 1
  • 10
  • 29
  • you can use [timedelta](https://docs.python.org/3/library/datetime.html#timedelta-objects) – Amjad Alsharafi Apr 04 '18 at 11:40
  • Check https://stackoverflow.com/a/4131114/302264 for an answer that seems to correctly solve the problem using only built-in Python libraries (it does use `calendar` though, which was not included in your request). – Eduardo Dobay Apr 04 '18 at 12:05

0 Answers0