Ultimately, datetime.timedelta(days, seconds) and timedelta(days, seconds) are the same thing.
Firstly, there is a module called datetime that contains several objects. If you do dir(datetime) you will see (at least in Python 2.7):
['MAXYEAR', 'MINYEAR', '__doc__', '__name__', '__package__', 'date', 'datetime', 'datetime_CAPI', 'time', 'timedelta', 'tzinfo']
You will note, then, that the datetime module contains two objects of interest; one also called datetime and one called timedelta. If you then did dir(datetime.datetime), you would see:
['__add__', '__class__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__ne__', '__new__', '__radd__', '__reduce__', '__reduce_ex__', '__repr__', '__rsub__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', 'astimezone', 'combine', 'ctime', 'date', 'day', 'dst', 'fromordinal', 'fromtimestamp', 'hour', 'isocalendar', 'isoformat', 'isoweekday', 'max', 'microsecond', 'min', 'minute', 'month', 'now', 'replace', 'resolution', 'second', 'strftime', 'strptime', 'time', 'timetuple', 'timetz', 'today', 'toordinal', 'tzinfo', 'tzname', 'utcfromtimestamp', 'utcnow', 'utcoffset', 'utctimetuple', 'weekday', 'year']
There is no timedelta in that list.
When you did from datetime import datetime, you did not import the datetime module to use but rather imported the datetime object. All references to datetime therefore refer to the object, which does not have timedelta as an attribute/method, hence the error.
Remembering the first list, there is no difference between the following:
from datetime import timedelta my_time = timedelta(0, 9780)
and
import datetime my_time = datetime.timedelta(0, 9780)
from datetime import datetimejust means that the seconddatetimemasks the module, hence the error withtimedelta. Just do something likeimport datetime as dtand then dodt.datetime.strftime()(or whatever it is you wantdatetimefor) anddt.timedelta()for example.