Date and Time python


#1



https://www.codecademy.com/courses/python-beginner-en-zFPOx/0/6?curriculum_id=4f89dab3d788890003000096#

Its says the date is not in the correct way


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)


#2

The string spacing and syntax should look like,

 '%s/%s/%s %s:%s:%s'

Not,

'%s:%s:%s:%s:%s:%s'

#3

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)

ops, 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 4)

File "python", line 4
print '%s/%s/%s/%s/%s/%s' % (now.month, now.day, now.year now.hour, now.minute, now.second)
^
SyntaxError: invalid syntax


#4

Your code is still incorrect because you wrote,

Instead of what I said,


#5

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


#6

No you need to look closely on how I have written the placeholders,

'%s/%s/%s %s:%s:%s'

What you are writing as a whole is,

'%s/%s/%s/%s/%s/%s'


#7

ok why do they change is it to sahow something is clock and the other is date


#8

Has it worked for you?


#9

like this print '%s/%s/%s %s:%s:%s' % (now.month, now.day, now.year now.hour, now.minute, now.second) still not working.


#11

File "python", line 4
print '%s/%s/%s %s:%s:%s' % (now.month, now.day, now.year now.hour, now.minute, now.second)
^
SyntaxError: invalid syntax


#12

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)


#13

You missed a comma between now.year and now.hour. :slight_smile:


#14

Cool thanks. Maybe im a bit to fast.


#15

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