I have a DATETIME field in SQL. Its content is: 2012-08-26 13:00:00
I want to know how much tim开发者_StackOverflow社区e has passed from that date until now.
In Python 2.7, it's easy:
import time,datetime
start = datetime.datetime.strptime('2012-08-26 13:00:00', '%Y-%m-%d %H:%M:%S')
end = datetime.datetime.now()
delta = start - end
print delta
But I have a web server running Python 2.4. In Python 2.4 strptime is not in the datetime module. I can't figure out how to accomplish the same thing in 2.4.
time.strptime is in Python 2.4. It returns a time tuple, which can be then converted to a datetime as shown below.
start = time.strptime('2012-08-26 13:00:00', '%Y-%m-%d %H:%M:%S')
start = datetime.datetime(*start[:6])
in python 2.4, the strptime()
function is located in the time
module.
精彩评论