datetime.date() vs datetime.date.today()
datetime.date() and datetime.date.today() are both Python Datetime Module APIs, and choosing between them is a common point of confusion. This page compares their syntax, parameters, return values, and typical use cases so you can pick the right one. datetime.date(): Creates a date object representing a specific date (year, month, day). Its syntax is datetime.date(year, month, day), and it returns date object datetime.date.today(): Returns the current local date. Its syntax is datetime.date.today(), and it returns date object Example of datetime.date(): from datetime import date
d = date(2024, 12, 25)
d.year # 2024
d.month # 12
d.day # 25. Example of datetime.date.today(): date.today() # date(2026, 6, 6). Read the full references for datetime.date() and datetime.date.today() to see parameters, edge cases, and example code side by side. Other Datetime Module APIs worth comparing: datetime.datetime.now(), datetime.datetime.utcnow(), datetime.datetime.fromtimestamp(), datetime.datetime.strptime(), datetime.datetime.strftime(), datetime.timedelta(). Both belong to the Datetime Module category in the Python Reference documentation.