Printing date and time


#1

I need help to execute this code below...I kept getting error...

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

instruction below as well...

Instructions

  1. On a new line, print now.year. Make sure you do it after setting the now variable!
  2. Then, print out now.month.
  3. Finally, print out now.day.

#2

This statement is overwriting the value you need to carry on further.

We do not really need any other variables. The now instance has a number of included attributes that already have a name and are easily referenced.

    now.year,
    now.month,
    now.day,
    now.hour,
    now.minute,
    now.second,
    now.microsecond

Our now values are static, a snapshot of the timestamp returned by datetime.now().


#3

@mtf...thanks for your thoughtful advice,


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.