Python Forum

Full Version: Time conversion error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I'm trying to convert "time" string and a code I wrote works fine until I add a print statement.
It produces error " print(datetime.timedelta(td_sec))
AttributeError: type object 'datetime.datetime' has no attribute 'timedelta'"
Code:
from datetime import datetime
# Some code here #
    if tstamp1 > tstamp2:   
        td = tstamp1 - tstamp2                                    
        tdif = str(td)
        print ("TIME Difference -------------------------------",tdif)
        td_sec = int(round(td.total_seconds()))
        td_sec=int(td_sec)
        print('The difference IN SEONDS  ---------%s seconds' % td_sec)
Print statement That produses the error:

print(datetime.timedelta(td_sec))
Thank you! Any help will be appreciated!
I found the solution thwt fixes the error:
print(timedelta(seconds=td_sec))
thank you!