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

Michal Janek
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Michal Janek
Front End Web Development Techdegree Graduate 30,654 Points

Strptime question

Kenneth mentions when showing strptime() while creating birthday that there is no hour in datetime, yet there are two 0,0 which were not typed in the string as it was:

'%Y-%m-%d' meaning we did not get hours back but why are those 0,0 there?

Can you explain clearer?

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

A datetime object has both a date and a time portion. If a time is not provided when the datetime is created, it is assumed to be 0 hour, 0 min: 12:00AM (midnight). The format guidance string is only used to interpret the source string. As long as there is sufficient information in the source string to create a datetime object based on the guidance string, then all other parameters are assumed to be zero.

Post back if this isn't clear enough.