0

I get this kind of result from MySQLdb - datetime.datetime(2015, 8, 13, 16, 52, 53)

How can I convert it into something readable, such as '2011-11-03 18:21:26'?

   # Open database connection
   db = MySQLdb.connect(user = "root", passwd = "xxx", db = "python", host = "127.0.0.1", cursorclass = MySQLdb.cursors.DictCursor)

   # prepare a cursor object using cursor() method
   cursor = db.cursor()

   # execute SQL query using execute() method.
   cursor.execute("SELECT * FROM users")

   # Fetch a single row using fetchone() method.
   data = cursor.fetchall()

   print data

result,

({'first_name': 'John', 'last_name': 'Smith', 'user_id': 4L, 'created_on': None, 'address': None, 'updated_on': datetime.datetime(2015, 8, 13, 16, 52, 53)}, {'first_name': 'Jane', 'last_name': 'Heart', 'user_id': 5L, 'created_on': None, 'address': None, 'updated_on': datetime.datetime(2015, 8, 13, 16, 52, 53)}, {'first_name': 'Dom', 'last_name': 'Robinsons', 'user_id': 6L, 'created_on': None, 'address': None, 'updated_on': datetime.datetime(2015, 8, 13, 16, 53, 33)}, {'first_name': 'Pete', 'last_name': 'Hand', 'user_id': 7L, 'created_on': None, 'address': None, 'updated_on': datetime.datetime(2015, 8, 13, 16, 53, 33)})

Run
  • 54,938
  • 169
  • 450
  • 748
  • Have you tried datetime.fromtimestamp instead? – Raul Reyes Aug 19 '15 at 02:27
  • 1
    I believe [this answer](http://stackoverflow.com/questions/14291636/what-is-the-proper-way-to-convert-between-mysql-datetime-and-python-timestamp) will point you to the right direction – Raul Reyes Aug 19 '15 at 02:41

0 Answers0