How to Get Current Year in Python?

Hello Dev’s today now in this short note i will be cover an python get current year. Here i will show this step by step also explain you how we can get current year in python. Now in this article, i will implement the how to get current year in python 3 application. I hope you can easily understand a concept of python get today year. We will do the following things for python get current year as a decimal number.

In this post, i will give you two basic examples to getting the current year in python. Here i will use datetime module to get the current year from date.

So let’s start and see the following examples:

Example 1:

main.py

from datetime import datetime
  
today = datetime.now()
  
print("Current Date and Time :", today)
print("Current Year :", today.year)
Example 2:

main.py

from datetime import datetime
  
today = datetime.now()
  
year = today.strftime("%-y")
print("Current Year as decimal number :", year);

Read Also: How To Implement Laravel 9 form validation ?

Thanks for read. I hope it help you. For more you can follow us on facebook

close

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →