user8929822
user8929822

Reputation: 323

Representing date format for three letter month in Python

How do I represent a 3 letter month date format in python such as the following:

Jan 16, 2012

I know for January 16, 2012 the format is %B %d,%Y. Any ideas?

Upvotes: 24

Views: 53767

Answers (3)

shadow
shadow

Reputation: 1

present_day = datetime.today()

present_day_string = present_day.strftime("%-d")

Upvotes: 0

Hao  XU
Hao XU

Reputation: 352

date_str = 'Jan 16, 2012'
date_components = date_str.split(' ')
date_components[0] = date_components[0][:3]
return ' '.join(date_components)

Upvotes: 1

Moses Koledoye
Moses Koledoye

Reputation: 78564

There's the three letter month format %b:

In [37]: datetime.strptime('Jan 16, 2012', '%b %d, %Y')
Out[37]: datetime.datetime(2012, 1, 16, 0, 0)

Upvotes: 56

Related Questions