>>> 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

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

thanks !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.