import time import datetime def compare_time(startTime,endTime): #now = datetime.datetime.now () d_start = datetime.datetime.strptime (startTime, '%Y-%m-%d %H:%M:%S') d_end = datetime.datetime.strptime (endTime, '%Y-%m-%d %H:%M:%S') diff = d_end - d_start #diff_days = -diff.days total_seconds = diff.total_seconds() #result = (d_start<=now) and (d_end>=now) #result = (d_start==d_end) #print(diff_days) return total_seconds ''' t1=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") time.sleep(3) t2=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") total_seconds=compare_time(t1,t2) print(total_seconds) '''