I have following code that gives output as "2020-07-30 15:59:17.535228", I would like to convert it from datetime into year and month format "20JUL" using python
I understand this is possible, I tried all possible changes but each time I'm getting some or other error...
Can you please guide..
Desired Output of below Python Code
20JUL
Python Code
from datetime import datetime
from dateutil.relativedelta import relativedelta, TH
todayte = datetime.today()
cmon = todayte.month
for i in range(1, 6):
t = todayte + relativedelta(weekday=TH(i))
if t.month != cmon:
# since t is exceeded we need last one which we can get by subtracting -2 since it is already a Thursday.
t = t + relativedelta(weekday=TH(-2))
break
import datetime
print(t)
thu = datetime.datetime.strptime('%Y-%m-%d %H:%M:%S.%f').strftime(date, '%Y-%m-%d')
print(thu)
The Code is giving following error
2020-07-30 15:59:17.535228
Traceback (most recent call last):
File "NextExpiryDatetry.py", line 138, in <module>
tame = datetime.datetime.strptime('%Y-%m-%d %H:%M:%S.%f').strftime(date, '%Y%M')
TypeError: strptime() takes exactly 2 arguments (1 given)