How to Get Current Month in 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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Get Current Year in Python?
- How to Get Current Date and Time in Python?
- How to Get Current Date in Python?
- Laravel Carbon Get All Dates Between Two Dates Example
- Laravel Carbon addYears() | Laravel Carbon Add Year Example
- Laravel Carbon Subtract Months from Date Example
- Laravel Carbon addMonths() | Laravel Carbon Add Months Example
- Laravel Carbon Subtract Days to Date Example
- Laravel Carbon Add Days to Date Example