How to Get Current Year in 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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Get Current Date in Python?
- Laravel Google Pie Chart Example Tutorial
- Laravel 9 One to One Relationship Example
- Laravel 9 QR Code Generator Example
- Laravel 9 Auth with Livewire Jetstream Example
- How to Add Days to Date in PHP?
- Laravel Seeder from CSV File Example
- Angular Get Difference Between Two Dates in Days
- How to use Bootstrap Datepicker in Angular 12?
- Moment JS Get Month Name from Date Example