Reputation: 323
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
Reputation: 1
present_day = datetime.today()
present_day_string = present_day.strftime("%-d")
Upvotes: 0
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
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