0

Python: Datetime

Greetings, I have a problem with datetime in Python. Why does the below code block fail? from datetime import datetime print datetime.now() BUT This one runs successfully? from datetime import datetime now = datetime.now() print (now) print (now.year) print (now.month) print (now.day)

1st Sep 2020, 7:08 AM
Adam Haller
Adam Haller - avatar
6 Answers
+ 4
Put a bracket after 'print'. Its working for me.
1st Sep 2020, 7:12 AM
Pranav Kalro
Pranav Kalro - avatar
+ 3
Adam Haller Yes Edit: But you can write it in this way too. import datetime print(datetime.datetime.now())
1st Sep 2020, 7:17 AM
Pranav Kalro
Pranav Kalro - avatar
+ 2
print(datetime.now()) will work
1st Sep 2020, 7:17 AM
Igor Kostrikin
Igor Kostrikin - avatar
+ 2
thank you very much guyss
1st Sep 2020, 7:23 AM
Adam Haller
Adam Haller - avatar
+ 1
Thank you very much... Pranav Kalro , so, do i also need to put from datetime?
1st Sep 2020, 7:14 AM
Adam Haller
Adam Haller - avatar
0
Version of python is changed from python2 to python3. So we have to use paranthesis after print function. print()
1st Sep 2020, 9:23 AM
Jenson Y