Created
June 14, 2018 18:18
-
-
Save 5263/774905606b262b67f6c4aed7a6b6eb94 to your computer and use it in GitHub Desktop.
Last day of previous months
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime,calendar | |
def ultimo(num=3,today=None): | |
"""return a list of datetime.date with the last day of num previous months""" | |
if today is None: | |
today = datetime.date.today() | |
return [datetime.date(y,m,calendar.monthrange(y,m)[1]) for \ | |
m,y in (((today.month - i -1) % 12+1, today.year + \ | |
((today.month - i -1) // 12)) for i in range(num+1,0,-1))] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment