Extracting information *Getting an error* Please help!


My code :

from datetime import datetime
now = datetime.now()
print datetime.now()
now = now.year
print now.year
now = now.month
print now.month
now = now.day
print now.day



now = now.year

now has a value of 2017, 2017.year will throw an error, integer 2017 doesn't have year attribute

this lines:

now = now.year
now = now.month
now = now.day

are wrong, they overwrite now with the wrong value throwing attributes error


so what should my code look like?
add the value variable now = 2017 and then 2017.year?


no? after doing this:

now = datetime.now()

now variable contains the current time and date, so you can just print now.year directly without doing this:

now = now.year

which will overwrite the current time and date with the year (integer)


that applies for month and date too?


oh wait. Got it! Thanks alot mate :slight_smile:


yes, now is not a string. its a datetime object, so once you overwrite, you are in trouble. Good you understand :slight_smile: