21 – Current date and time#
The modue datetime has data types that you can use to represent pure dates or dates with times:
datetime.datedatetime.datetime
Each class has a class method that gives you an instance of that class with the current date (and time), respectively:
datetime.date.todaydatetime.datetime.now
import datetime as dt
today = dt.date.today()
print(today) # 2025-04-05
now = dt.datetime.now()
print(now) # 2025-04-05 19:29:13.437736