ItSolutionStuff.com

How to Get Current Year in Python?

By Hardik Savani • October 30, 2023
Python

Hi Dev,

In this short tutorial we will cover an python get current year. step by step explain how to get current year in python. In this article, we will implement a how to get current year in python 3. you can understand a concept of python get today year. you will do the following things for python get current year as decimal number.

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

I hope it can help you...

Tags: Python
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

How to Get Current Date in Python?

Read Now →

Laravel Google Pie Chart Example Tutorial

Read Now →

Laravel 9 One to One Relationship Example

Read Now →

Laravel 9 QR Code Generator Example

Read Now →

Laravel 9 Auth with Livewire Jetstream Example

Read Now →

How to Add Days to Date in PHP?

Read Now →

Laravel Seeder from CSV File Example

Read Now →

Angular Get Difference Between Two Dates in Days

Read Now →

How to use Bootstrap Datepicker in Angular 12?

Read Now →

Moment JS Get Month Name from Date Example

Read Now →