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 () in the top-right of this page. Still can’t find it? Ask it below by hitting the reply button below this post ().
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.
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
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
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()
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.