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 Manipulating Time Already

Why does Kenneth's example exclude Microseconds?

I'd guess that this has something to do with the version of Python I'm currently running in 2023, VS what Kenneth was running back in 2014 in this video - Regardless, my question is:

When Kenneth replaces parameters in treehouse_start, and calls treehouse_start, the repl prints: datetime.datetime(2014, 10, 15, 9, 0)

When I replace the parameters and treehouse_start in my repl, it prints: datetime.datetime(2023, 3, 7, 9, 0, 37)

I'm curious why mine prints seconds, while Kenneth's example only prints year, month, day, hour, minute. I also don't understand why my seconds are printed as 37 when I've set it to 0. Thoughts?

1 Answer

Steven Parker
Steven Parker
229,920 Points

I don't think a newer Python version is any different in this regard.

Did you perhaps set "seconds" accidentally? The correct term is "second" (singular).

And your seconds are showing because they are non-zero. The default display omits microseconds and seconds if they are zero.

Thanks for your help, Steven! That makes sense that seconds appeared for me given they were set to 37.

I just tried to reproduce this issue, but my results are the same as Kenneth's now. I did attempt to set "seconds" instead of "second"; it threw a TypeError: 'seconds' is an invalid keyword argument for replace().

I'm on a different computer now than when I was working last night - maybe that has something to do with it, maybe I hit an intermittent bug, or maybe I did something funky that didn't stand out to me last night that I'm not doing now.

No matter - thanks for your time & help!