Date and Time 6/6


#1

Hi, i was wondering if I am doing anything wrong.
from datetime import datetime
now = datetime.now()

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

^^^^^^^^^^^^^^^^^^
please let me know :smile :smile:


#2

you need to write it like this
print '%s/%s/%s %s:%s:%s' % (now.month, now.day, now.year,now.hour, now.month, now.second,)

What you are writing is simply what they are showing you have learned so far.


#3

I wrote exactly that and even copied and pasted what you had and it still doesn't work. Please help !


#4

Hey, hope it's not too late.

# from datetime import datetime     looks up the time/date
# now = datetime.now()     sets the time/date equal to now.timepart

# print     prints the statement
# this '00/00/00 00:00:00' is our desired format, so replace each 00 with %s (don't forget quotes) to start your statement
# % replaces each %s with a variable
# (now.month, now.day, now.year, now.hour, now.minute, now.second) is our list of variables

I'm not sure what exactly is going wrong with the suggested code, but it's very close to correct.


#5

Hi I did this and it says invalid syntax. I still don’t understand syntax. Please help. (i.e.)
print '%s/%s/%s %s:%s:%s' % (now.month, now.day, now.year,now.hour, now.month, now.second
thanks Nichola


#6

Hi, @nicwo ,

Syntax relates to the rules for constructing statements in a language.

Did you close the parentheses in your statement?


#7

Can you show us exactly what your code looks like, and the entire error message that's showing up?