0

I'm trying to get the time in seconds between the current time, and a timestamp (datetime) I have in my database, but I can't seem to get it working..

config = json.loads(open('/var/www/html/config.json').read())
db = MySQLdb.connect(config['database']['host'],config['database']['user'],config['database']['password'],config['database']['dbname'] )
cursor = db.cursor()
sql = "select MANTIME from weather_settings"
cursor.execute(sql)
global delay
fetched = cursor.fetchone()
data = fetched[0]
cursor.close()
db.close()
dbtime = data
print("Current db time is: ",dbtime)
print("")
nowtime = time.strftime("%Y-%m-%d %H:%M:%S")
nowtime = datetime.strptime(nowtime,"%Y-%m-%d %H:%M:%S")
print("Current time is: ",nowtime)
print("")
difference = nowtime - dbtime
print("The difference is: ",difference)
print("")
if int(difference)/60 > 27:
    print("Time exceeds 27 minutes")
else:
    print("Time doesn't exceed 27 minutes") 

This gives me this type error: TypeError: int() argument must be a string or a number, not 'datetime.timedelta'

I can't seem to figure it out, and the code I have now is probably not very nice.

Can anyone help me with how to take the current date and time, and compare it with the date and time of a datetime in my database, and return the seconds between them?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Bill Skullman
  • 33
  • 1
  • 7

0 Answers0