3
from datetime import datetime
current_time = datetime.now()

print "%s-%s-%s" % (current_time.month, current_time.day current_time.year,)
#Will print the current date in a mm/dd/yyyy format.

input()

The code above is meant to print out the current date in a mm/dd/yyyy format in a command prompt. So for example if this actually worked it would open up a command prompt window that printed out; for example the current date as im writing this like this: 8-5-2017

I keep getting this error when trying to run the module that the closing " in "%s-%s-%s" that it's invalid syntax. Is python 3 using something different from this or did I make a mistake?

cs95
  • 330,695
  • 80
  • 606
  • 657
Volerm
  • 47
  • 1
  • 1
  • 2

1 Answers1

10

In python3, print statements require braces.

Furthermore, if you're looking to print the data, just use datetime.strftime

In [340]: print(current_time.strftime('%m/%d/%Y'))
Out[340]: '08/05/2017'
Azat Ibrakov
  • 8,514
  • 9
  • 36
  • 44
cs95
  • 330,695
  • 80
  • 606
  • 657
  • Thanks, I forgot that print required brackets. Too much time on code academy and not using the editor slipped me up on that. – Volerm Aug 05 '17 at 08:10