Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Dates and Times in Python (2014) Dates and Times now() and .replace()

gregory fenwick
gregory fenwick
7,569 Points

AttributeError: type object 'datetime.datetime' has no attribute.

I tried using multiple import methods:

import datetime from datetime import datetime from datetime import datetime as dt

Having problems running test script as below:

Have tried recommendations here: http://stackoverflow.com/questions/11983609/how-to-fix-issue-with-datetime-datetime-which-has-no-attribute-timedelta

Any further assistance would be appreciated.

from datetime import datetime

now = datetime.now()

print(now)

delta = datetime.timedelta(hours=5)

print(delta)

1 Answer

Kourosh Raeen
Kourosh Raeen
23,733 Points

Hi Gregory - For this challenge you don't need timedelta. The only import you need is:

import datetime

Once you create the variable now you can do the last two tasks using replace().

gregory fenwick
gregory fenwick
7,569 Points

Thanks Kourosh. It was not so much for the challenge, it was more to do with my setup, where I use Python on my MAC and within the environment, I could only get this to work on the actual python console rather than running as an actual script. Normally I will write a script first and test, before using the challenges etc.