I need to store an uptime in a mysql environment. The uptime can vary from a few hours to more than one year. I was considering using a DATETIME type for mysql. I'm working with python, and the uptime is obtained from
def convertdate(lastrestart):
# now in datetime
nowdt=datetime.now()
# last_restarted in datetime
lastrestarted_dt=datetime.strptime(lastrestart, "%Y-%m-%d %H:%M:%S")
# timedelta in datetime!
uptimeInDT=nowdt-lastrestarted_dt
#timedelta in seconds
secondsUptime=uptimeInDT.seconds
# string conversion wont work so much for a datetime field.
print str(uptimeInDT)
Is this the best way for doing this job? Sould I use other solutions? SEC_TO_TIME() in mysql has a smaller range and wont work, and there's no function from sec to datetime. Maybe I should save the seconds and get used to that. Thanks