Python - Convert mysql datatime

1

I'm trying to compare the current date with the last record date of my mysql database:

sql2 = "SELECT created_at FROM tempaverage WHERE created_at IN (SELECT max(created_at) FROM tempaverage)"
  cursor.execute(sql2)
  current = strftime("%Y-%m-%d %H:%M:%S", gmtime())
  for (created_at) in cursor:
    diff = current-created_at
    print diff

But it does not return anything when I make print diff because it exits the exception, and if it does print created_at the value is > (datetime.datetime(2015, 3, 4, 11, 45, 3),)

How can I compare dates?

    
asked by anonymous 04.03.2015 / 15:12

1 answer

1

I solved by not using the: strftime("%Y-%m-%d %H:%M:%S", gmtime())

Then you can use: datetime.datetime.now()

  current = datetime.datetime.now()
  for x in range(0,numrows):
    row = cursor.fetchone()
    created_at = row[0]
    diff = (current-created_at).seconds/60       
    
04.03.2015 / 16:12