Can I display the month name instead of a number?



Can I display the month name instead of a number?


Yes! By default we’re accessing the number value of the current month, day, year, minute, hour, and second of the day. We can customize a lot of how we display this.
We format the output using strftime(), which won’t be discussed on Codecademy, but it’s a cool tool to have! For a full understanding of how to do it, take a look at the documentation for this method.
Take a look at the code below:

from datetime import datetime

now =

print(now.strftime('%B'))   # Displays the current month’s name

The code %B tells strftime() that we want to display the month as its full name, and there are lots of other codes ready for use in the link above.

FAQ: Learn Python -Date and Time- Extracting Information

When I type

now =
print now

I get

2018-08-16 13:00:42.874437

But when I type

print now.second

i get


How can i get the digits after the decimal in the seconds field?


if you check the documentation:

you see that you can use microsecond to get this information


Why do we use brackets in the first example but not the second?

now =
now_year= now.year


because .now() is a method, while year is an instance variable. But to fully grasps this concept you need to understand classes. Regardless, here is an example:

class datetime(object):

    def now(cls):
        cls.year = 2018
        return datetime()

time =
print time.year

maybe not an entirely accurate representation, but it gives you an idea (hopefully), otherwise come back to this later


Can we extract the year, month, etc. without storing in a variable?


Hi @cyphered.daydream,

Yes, you can do this, but making six function calls is less efficient than making just one call, and saving the result to a variable for output …

from datetime import datetime

print '%4d/%02d/%02d %02d:%02d:%02d' % (,,,,,

Output …

2018/10/14 14:00:46

Edited on 2018/10/14 to consolidate the Python code for better display.