0

>>> line = '2008-10-27 12:05:54...........
>>> time = line.split(' ')[1].split('.')[0]
>>> print time
12:05:54

i would like to add 45 or so minutes to the time i am parsing from a line
i have tried
print time.timedelta(minutes=45)

Traceback (most recent call last):
File "<pyshell#44>", line 1, in <module>
print time.timedelta(minutes=45)
AttributeError: 'str' object has no attribute 'timedelta'

i have imported all the needed modules. where am i wrong

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by axn
0

Sometimes it's easier to show some code:

import time, datetime

data = '2008-10-27 12:05:54'
fmt = '%Y-%m-%d %H:%M:%S'

ts1 = time.strptime(data, fmt)

dt1 = datetime.datetime(*time.strptime(data, fmt)[:6])

dt2 = datetime.datetime(*time.strptime(data, fmt)[:6])+datetime.timedelta(minutes=45)

print "%s:%s:%s" % (dt2.hour, dt2.minute, dt2.second)

Output:

>>> 12:50:54
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.