Your object mydatetime
is surrounded by quotes: it's a string. Just drop the quotes:
myDateTime = datetime.datetime(2012, 11, 16, 3, 0)
myDatetime.strftime("%Y-%m-%d %H:%M:%S")
If mydatetime
is the output of a function that returns a string (such as your SQL query), you could try to use eval
to transform it into a regular Python object. BE VERY CAREFUL, though, as eval
is not secure at all. You may want to use the third-party module asteval
instead.