I want to get only the months from the given date. For example, given a date 2021-02-14, to be transformed to 'February'.
Asked
Active
Viewed 614 times
-1
-
near-dupe: [Get month name from number](https://stackoverflow.com/q/6557553/10197418), see [this answer](https://stackoverflow.com/a/6557568/10197418). – FObersteiner Jul 28 '21 at 09:49
2 Answers
0
You get the Number of the month by datetime.datetime.month. To make this into the String 'February', you would need a dictionary. See the docs of the datetime class for more information.

ductTapeIsMagic
- 113
- 1
- 8
0
You can use datetime.strftime
with %B
to get the month name as you need
See an example below,
import datetime
date = "2020-01-01"
date_obj = datetime.datetime.strptime(date, "%Y-%m-%d")
datetime.datetime.strftime(date_obj, "%B") # January

Sreeram TP
- 11,346
- 7
- 54
- 108