FAQ: Learn Python - Date and Time - Hot Date

This community-built FAQ covers the “Hot Date” exercise in Codecademy’s lessons on Python.

FAQs for the Codecademy Python exercise Hot Date:

Join the Discussion. We Want to Hear From You!

Have a new question or can answer someone else’s? Reply (reply) to an existing thread!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources about Python in general? Go here!

Want to take the conversation in a totally different direction? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account, billing, Pro, or Pro Intensive? Reach out to our support team!

None of the above? Find out where to ask other questions here!

Other FAQs

The following are links to additional questions that our community has asked about this exercise:

  • This list will contain other frequently asked questions that aren’t quite as popular as the ones above.
  • Currently there have not been enough questions asked and answered about this exercise to populate this FAQ section.
  • This FAQ is built and maintained by you, the Codecademy community – help yourself and other learners like you by contributing!

Not seeing your question? It may still have been asked before – try searching for it by clicking the spyglass icon (search) in the top-right of this page. Still can’t find it? Ask it below by hitting the reply button below this post (reply).

2 posts were split to a new topic: Why do I Get This Output?

How come codeademy wants you to use 02d% or 04d% instead of %s?
print '%02d/%02d/%04d' % (now.month, now.day, now.year)
print '%s/%s/%s' % (now.month, now.day, now.year)
They both get the output of 3/22/2019

I guess what im really asking is what is the difference between the %s and the %0#?
Thanks in advance.

3 Likes

Hi, I used this piece of code and displays the actual date in the console in the right way that the exercise is asking but it said to me that the code is wrong, why?: from datetime import
datetime
now =datatime.now

print “%02d, %02d, %04d” % (now.month, now.day, now.year)

I tested your method. The difference is the way that the lesson suggests inserts a 0 before single-digit months and dates (e.g. 04/30/2020 vs. 4/30/2020). Not sure why you need %4d before the year, though.

say you have a 1-4 digit number line, you would need to use %04d so you can have both numbers in. example:the year is 1, so in the editor, you would get 0001 as your answer.
this lets you have specific digits to your coding unlike the %s

because (for now) a year will be only 4 digits.and you wouldnt want to accidently get a year with 5 digits.

2 Likes

I tried using %02d instead of %04d for the year but still got the same result. Should I be getting an error here?

1 Like

Hello, @blog6952103350, and welcome to the Codecademy Forums!

The %04d format specifier means that the corresponding integer should be presented with at least four digits. If that integer contains fewer than four digits, then zeroes are supplied on the left to fill it to four digits.

The %02d format specifier is similar, except that it would only need to be filled to two digits.

With those format specifiers, if the corresponding integer has a number of digits that exceeds what is given in the format specifier, all of the digits are presented anyway. With the year, it did not matter so much, since it already has the four digits that we wish to present. That might be why Codecademy’s submission correctness test for this exercise accepted your answer. With the other components, we do want a leading zero when they have only one digit, so the %02d format specifier is needed for each of them.

Hi, I had a problem with the code. I got the wrong date for the exercise, even though I followed the directions exactly, and I was wondering if there was a way to fix that.
[/codebyte]

from datetime import datetime
now = datetime.now()

print ‘%02d/%02d/%04d’ % (now.month, now.day, now.year)

[/codebyte]

This code resulted in the date being a day later.

Hello! I don’t like the fact that it only accepts MM/DD/YYYY format, which is used mostly in the United States. In most countries, we use YYYY/MM/DD format, or DD/MM/YYYY format.

I’d like to be able to use the format I’m used to.