Help with time and date python

Hi,
I wrote the following code:

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

for some reason that I dont understand I am getting the following error:
File “python”, line 3, in
ValueError: unsupported format character ‘/’ (0x2f) at index 4

since when isnt this not supported?
Also, when I represent the same code but in single string like this:

print ‘%02d/%02d/%04d %02d:%02d:%02d’ % (now.month, now.day, now.year, now.hour, now.minute, now.second)
it works fine.
any ideas?
Thanks

could u give me a screenshot of your problem i might beable to help u better

Ah, but you haven’t written the same thing though, have you?

The way you’ve written it when it’s throwing an error is like this:

02d%/02d%/04d%

but when you’ve done it as a single print statement, you’ve written this:

%02d/%02d/%04d %02d:%02d:%02d

Look closely at the position of the % symbols, which denote your chosen format character. Can you see why you’re getting the error now?

The OP has posted the code and the traceback; that’s more than enough to identify the problem here. :slight_smile: