09-Aug-2022
.
Admin
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
#Python