How to Get Current Month in Python?

By Hardik Savani October 30, 2023 Category : Python

Hi Dev,

In this short tutorial we will cover an python get current month. step by step explain how to get current month in python. In this article, we will implement a how to get current month in python 3. you can understand a concept of python get today month. you will do the following things for python get current month as decimal number.

In this post, i will give you three examples to getting current month in python. we will use datetime module to get current month from date. so let's see following examples with output:

Example 1:

main.py

from datetime import datetime
  
today = datetime.now()
  
print("Current Date and Time :", today)
print("Current Month :", today.month)

Output:

Current Date and Time : 2022-06-01 09:19:25.514112
Current Month : 6

Example 2:

main.py

from datetime import datetime
  
today = datetime.now()
    
month1 = today.strftime("%b")
print("Current Month Full Name:", month1);
  
month2 = today.strftime("%b")
print("Current Month Abbreviated Name:", month2);
  
month3 = today.strftime("%m")
print("Current Month with Decimal Number :", month3);

Output:

Current Month Full Name: January
Current Month Abbreviated Name: Jan
Current Month with Decimal Number : 01

I hope it can help you...

Tags :
Shares