Domanda

learning to code with python I'm stuck getting datetime not defined error. Im on codecademy googled all around and not seeing where my code is wrong...sorry for my newbieness in advance and thanks for your help.

Instructions:
Print the current date in the form of mm/dd/yyyy. 

my code:

import datetime
now = datetime.now()
print now

current_month = now.month
current_day = now.day
current_year = now.year


print str(current_month)+"/"+str(current_day)+"/"+str(current_year)
È stato utile?

Soluzione 2

It should be

import datetime
now = datetime.datetime.now()
print now

Altri suggerimenti

change your import to:

from datetime import datetime
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top