How do I turn a python datetime into a string, with readable format date?

TIMEX picture TIMEX · Jan 28, 2010 · Viewed 319.7k times · Source
t = e['updated_parsed']
dt = datetime.datetime(t[0],t[1],t[2],t[3],t[4],t[5],t[6]
print dt
>>>2010-01-28 08:39:49.000003

How do I turn that into a string?:

"January 28, 2010"

Answer

Cristian picture Cristian · Jan 28, 2010

The datetime class has a method strftime. The Python docs documents the different formats it accepts:

For this specific example, it would look something like:

my_datetime.strftime("%B %d, %Y")