Python grand finale date and time


#1

it says to put the date and time together on one line

this is what i put:

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

this is what it's telling me

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

please help!


#2

you forgot point between now and second , No ??


#3

oh ya i did but i just fixed that and it's still saying the same thing


#4

again you add & in %s/&s/%s , replace it by %


#5

so the correct code wil be :

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

#6

Thanks azazaz, that was the correct answer! I was stuck.


#7

now = datetime.now()
print ‘%02d/%02d/%04d’ ‘%02d:%02d:%02d’ % (now.month, now.day, now.year, now.hour, now.minute, now.second)

Here’s my code and it does print onto the console, however, this how they are printed.
03/23/201813:39:20

What am I doing wrong, please help.


#8

One way to fix the problem you are encountering is to simply add a space between the two semantic parts of formatting. Like this:

print '%02d-%02d-%04d %02d:%02d:%02d' % (now.month, now.day, now.year, now.hour, now.minute, now.second) 

#9

Hi Jon,
What does 02d 04d stand for? What is more convenient when using %s instead of %02d