3

I have a DATETIME field in SQL. Its content is: 2012-08-26 13:00:00

I want to know how much time 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.

glglgl
  • 89,107
  • 13
  • 149
  • 217
1qazxsw2
  • 2,589
  • 4
  • 20
  • 19

2 Answers2

11

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])
unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677
0

in python 2.4, the strptime() function is located in the time module.

Adrien Plisson
  • 22,486
  • 6
  • 42
  • 73