-2

How exactly should the code look like if I want to receive only the date in EET-format (09.10.2016) by using datetime module in python 3.4.3 IDE?

It works with:

from datetime import datetime 
sa = datetime.now ()

print (sa.day, sa.month, sa.year)

but the result is 09 10 2016 In this case there are missing the two dots between the day.month.year

I am trying with:

from datetime import datetime
sa = datetime.now ()

print '%s/%s/%s' % (sa.day, sa.month, sa.year)

in hope to change the dots with slashes, but receiving 'syntax error'

Why?

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
ccsan
  • 1

2 Answers2

0

The problem is the print function. How are you using Python 3, you should use parenthesis in the print function.

from datetime import datetime 
sa = datetime.now () 
print ("%s.%s.%s" % (sa.day, sa.month, sa.year))

Output:

9.10.2016

Jose Raul Barreras
  • 849
  • 1
  • 13
  • 19
0

because you are using python 3, and print is a function there.

print('%s/%s/%s' % (sa.day, sa.month, sa.year))
Alex
  • 1,141
  • 8
  • 13