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

When will this method ever be useful?

can't we just use what we learned in the previous lesson to enter in a specific date and time, when will we need to convert the date and time from string format?

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi, Adrian Diaz! Being able to make a new datetime object from a string is very useful. I know that it may not seem like it now. But Python, besides just being a generic purpose scripting language and good for data analysis, can also be used for web development.

Imagine a scenario where we have a web form and we ask users for their birthday. Anything they type in that input field will be a string naturally. Now we can format that how we wish, and validate it etc, but it's still a string. But when we save it to the database, we want to save it as a datetime object. Maybe a week before their birthday we want to send out a coupon for our services or some other small birthday bonus. There are all kinds of calculations you can do when the date is a datetime object as opposed to just a string.

Hope this helps! :sparkles: