Date and time confusion


Your code looks a bit off. Check the Hint if you need help! Your
code threw the following error: invalid syntax (python, line 5)

from datetime import datetime
now =

print '%s/%s/%s' % (now.month,, now.year)
print '%s:%s:%s' % (now.hour, now.minute, now.second)


Exercise 6 wants you to print the date and time out on one line.

7/17/2016 8:29:26


thats what i need help with i know im supposed to do that but i don't know how


@xxserpentsxxyt printing your code like this:

Will give you the output like this:


Do you see how writing the values on two separate lines gives you the answer back on two separate lines as well? If you write everything on one line, it will print it back on one line as well, so your code should look line this:

from datetime import datetime
now =

print '%s/%s/%s %s:%s:%s' % ( now.month, , now.year, now.hour, now.minute, now.second)

Do you understand why you had to write it like that? Let me know if you didn't or need more help.

Good luck and happy coding! :slight_smile:

-- @chipjumper36731


I wrote the code like that and it combined the year with the hour instead of having a space in between.

print '%s/%s/%s' '%s:%s:%s' % (now. month,, now.year, now.hour, now.minute, now.second)

which gives me this 7/18/201622:12:35

instead of this 7/18/2016 22:12:35


Nevermind, i got it to work


Okay :slight_smile: Keep coding!


interesting side note, without the space before now.month my code didn't work, it seems that without it the now.minute wrapped as now on one line and .minute on the next causing it to fail


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.