In Python, you can convert a datetime
object to a date
object by using the .date()
method. Here’s an example:
from datetime import datetime
# Sample datetime object
dt = datetime(2025, 1, 22, 15, 30, 45)
# Convert datetime to date
date_only = dt.date()
print(date_only)
Output:
2025-01-22
The .date()
method will extract the date part (year, month, and day) from the datetime
object and return it as a date
object.