Python Get Current Year Example
Aug 09, 2022
Hi Dev,
This article will provide example of Python Get Current Year Example. if you want to see example of Python Get Current Year then you are a right place. you will learn How to Get Current Year in Python. I would like to share with you Python Get Today Year.
In this post,i will give you three examples to getting current year in python. we will use datetime module to get current year 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 Year :", today.year)
Output:
Current Date and Time : 2022-05-31 09:21:35.126001
Current Year : 2022
Example 2:
main.py
from datetime import datetime
today = datetime.now()
year = today.strftime("%-y")
print("Current Year as decimal number :", year);
Output:
Current Year as decimal number : 22
- Get Last 2 Digits of Number in Python Tutorial Example
- How to Sum of First and Last Digit of Number in Python?
- How to Get First and Last Digit of Number in Python?
- Get the Last Digit of Number in Python Tutorial Example
- Get the First Digit of Number in Python Tutorial Example
- How to Remove All Decimals from Number in Python?
- How to Convert String to Float with 2 Decimal Places in Python?
- How to Format Number to 2 Decimal Places in Python?