How to get a current year in Python
In this tutorial, we are going to learn about how to get the current year in Python.
Getting the current year
To get the current year in Python, first we need to import the date
class from the datetime
module and call a today().year
property on it.
The year
property returns the current year in four-digit(2023) string format according to the user’s local time.
Here is an example:
from datetime import date
current_year = date.today().year
print(current_year)
Output:
2023