Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert python abbreviated month name to full name

How can I convert an abbreviated month anme e.g. Apr in python to the full name?

like image 386
user308827 Avatar asked Oct 17 '16 00:10

user308827


People also ask

Which format will display full month name in Python?

Method #1 : Using strftime() + %B In this, we use strftime() which converts date object to a string using a format, and by providing %B, it's enforced to just return a Month Name.

How do I change the month format in Python?

Use strftime() function of a datetime class For example, the %d-%m-%Y %H:%M:%S codes convert date to dd-mm-yyyy hh:mm:ss format.

How do you abbreviate month names in Python?

Passing "%b" to strftime returns abbreviated month name while using "%B" returns full month name.


1 Answers

If you insist on using datetime as per your tags, you can convert the short version of the month to a datetime object, then reformat it with the full name:

import datetime
datetime.datetime.strptime('apr','%b').strftime('%B')
like image 178