https://stackoverflow.com/questions/9724906/python-date-of-the-previous-month
https://docs.python.org/ko/3/library/datetime.html
import datetime
import dateutil.relativedelta
or you can write down
from datetime import datetime
anyway , you have to import datetime
print(now + dateutil.relativedelta.relativedelta(months=-1))
2020-05-26 12:35:28.132035
as another example
rint(now + dateutil.relativedelta.relativedelta(months=-8))
2019-10-26 12:35:28.132035
the only thing that changes months=
understand ?? :) awsome
In [10]: datetime.now().year
Out[10]: 2020
In [11]: datetime.now().month
Out[11]: 6
right!
from datetime import datetime
import dateutil.relativedelta
now = datetime.now()
year = datetime.now().year
month = datetime.now().month
day = str(now + dateutil.relativedelta.relativedelta(months=-1)).split()[0].replace("-","")
print(day) # 20200526
from datetime import datetime
import dateutil.relativedelta
now = datetime.now()
year = datetime.now().year
month = datetime.now().month
day = str(now + dateutil.relativedelta.relativedelta(months=-1)).split()[0].replace("-", "")
print(day) # 20200526
print(day[:6]) # 202005
I can't English well.
however, I think these things are piled up and become better later.
i love google translator
haha :)
datetime.datetime(2020, 9, 10, 16, 47, 4, 330672, tzinfo=<UTC>)
In [8]: date.month
Out[8]: 9
In [9]: date.year
Out[9]: 2020
In [10]: date.year
Out[10]: 2020
In [11]: date.month
Out[11]: 9
In [12]: date.day
Out[12]: 10
4자리 year
now.strftime("%Y") # 2020
2자리 year
now.strftime("%y") # 20
2자리 month
now.strftime("%m") # 11
1자리 month
"{:d}".format(now.month) # 5
2자리 day
now.strftime("%d")
import calendar
print(calendar.calendar(2020))
# 달력정보 모두 출력
import calendar
calendar.prmonth(2020,10)
import calendar
calendar.weekday(2020,7,13)
# 0 = 월요일
# 1 = 화요일
# 2 = 수요일
# 3 = 목요일
# 4 = 금요일
# 5 = 토요일
# 6 = 일요일