How to Get Current Year in Python?
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:
from datetime import datetime today = datetime.now() print("Current Date and Time :", today) print("Current Year :", today.year)
Current Date and Time : 2022-05-31 09:21:35.126001 Current Year : 2022
from datetime import datetime today = datetime.now() year = today.strftime("%-y") print("Current Year as decimal number :", year);
Current Year as decimal number : 22
I hope it can help you...
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