0

I'm trying to go back December month but my results are month 0 instead of month 12... how can I do that? I create a code and on it I need the Today date and also the last day of the before month, I mean: for example today is 25/01/2018 and I need 31/12/2017. On February I'm going to run it again and I need for example 25/02/2018 and 31/01/2018. That is the relationship I'm looking for

import datetime
fecha17 = time.strftime(str((int(time.strftime("%d")))-1) +"/" + str((int(time.strftime("%m")))-1) + "/%Y")
Martin Bouhier
  • 361
  • 2
  • 6
  • 19
  • 1
    Possible duplicate of [python date of the previous month](https://stackoverflow.com/q/9724906/953482) – Kevin Jan 25 '18 at 13:13
  • 2
    Possible duplicate of [python date of the previous month](https://stackoverflow.com/questions/9724906/python-date-of-the-previous-month) – Taku Jan 25 '18 at 13:13
  • You have another issue - you import `datetime` but try to call methods of `time`. – Psytho Jan 25 '18 at 13:14
  • 2
    Adding/subtracting dates manually isn't a good idea, you'll be better off adding/subtracting `timedelta` instead. – Taku Jan 25 '18 at 13:16

0 Answers0