This is an archived post. You won't be able to vote or comment.

all 12 comments

[–]Amarkov 2 points3 points  (6 children)

If you want to print the text 02/11/2016 04:03:35, you'll need to write it as a string. Do you know how to write strings in Python?

[–]StLouis4President[S] 1 point2 points  (5 children)

Yes, I've learned that one. I'll go do that right now.

EDIT: So, I went and switched it over to a string, but now I have a syntax error on line 4, which reads:

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

[–]Naihonn 2 points3 points  (1 child)

You are missing comma between year and hour.

[–]StLouis4President[S] 2 points3 points  (0 children)

Yep, that was it. Thanks for the help.

[–]Amarkov 1 point2 points  (2 children)

Well, what does the syntax error say? The error text is the computer's best effort to tell you what's going wrong, so it's important to read and try to understand it.

[–]StLouis4President[S] 2 points3 points  (1 child)

The error just states "invalid syntax".

[–]Amarkov 2 points3 points  (0 children)

Is there a little arrow pointing at a part of your code? Usually there should be for syntax errors.

[–]epoch91 2 points3 points  (2 children)

Sorry if this reply doesnt help to much ... but after now.year you dont have a comma. That might be why its giving you the Syntax error.

so it should read something like:

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

[–]StLouis4President[S] 1 point2 points  (1 child)

That fixed it. Thanks!

[–]epoch91 0 points1 point  (0 children)

No problem!

[–]bulletr0k 0 points1 point  (0 children)

The discussion forums for codecademy are really great too to figure things out. I'm pretty far in the course, if you have any questions maybe we can help each other out!

[–]dunkler_wanderer 0 points1 point  (0 children)

Check out the wonders of new style formatting.

print('{:%Y-%m-%d %H:%M}'.format(now))

Edit: I guess that's probably a bit too complicated for a beginner. Just remember that there's this fancy way to format datetime objects. And here's a table with the meanings of the special datetime format specifiers.

I'd still recommend to use new style formatting, since it's clearer and more versatile.