datetime - str to time in python -
time1 = "2010-04-20 10:07:30" time2 = "2010-04-21 10:07:30"
how convert above string time stamp?
i need subtract above timestamps time2-time1
.
for python 2.5+
from datetime import datetime format = '%y-%m-%d %h:%m:%s' print datetime.strptime(time2, format) - datetime.strptime(time1, format) # 1 day, 0:00:00
edit: python 2.4
import time format = '%y-%m-%d %h:%m:%s' print time.mktime(time.strptime(time2, format)) - time.mktime(time.strptime(time1, format)) # 86400.0
Comments
Post a Comment