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

Leo Marco Corpuz
Leo Marco Corpuz
18,975 Points

Datetime question

Lately, I’m not understanding why we’re using dot notation on datetime twice. (Example. datetime.datetime.now()). The answer for the the next challenge (second task) requires using dot notation twice on datetime before adding the strftime method.

2 Answers

19,363 Points

It was confusing at first to me too but to make it easier imagine we import datetime as dt. The module dt (datetime) has a method called datetime and others too such as date, time, timedelta, etc... From there you can call dt.datetime.now() or many others, here's some examples.

I recommend reading this explanation, explains it much better than I can

import datetime as dt