Python Get Current Year Example Tutorial

Published On: 26/08/2022 | Category: Python


Hi Guys,

Today, I will let you know example of python get current year example. you can understand a concept of how to get current year in python. This article goes in detailed on how to get current year in python 3. I explained simply about python get today year. Alright, let’s dive into the steps.

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:

So let's see bellow example:

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-08-26 04:38:10.488591
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

It will help you....