Let’s say, we have this date 2022-01-01. How can I remove days part from it to get 2022-01?
I’ve already tried using strptime '{:%Y-%m}'.format(dt.strptime(currentDate, '%Y-%m-%d')) but it gives me this error TypeError: strptime() argument 1 must be str, not datetime.date
>Solution :
Use strftime method:
import datetime as dt
date_object = dt.datetime(2022, 1, 1)
output = date_object.strftime('%Y-%m')
print(output) # 2022-01