The datetime.date() function in Python

The datetime.date() function in Python creates a date instance out of a datetime instance.

Time and Date Updated 13 Feb 2017 1 min read

Method Name

date

Method Signature

date()

Method Overview

  • The date() instance method of the python datetime class returns a date instance.
  • Using this method only the date information excluding the time information is retrieved from a datetime instance.

Example

python
import datetime

# Create a datetime instance

datetimeInstance = datetime.datetime.today()

# Get only the date instance from datetime instance

dateInstance = datetimeInstance.date()

# Print the datetime instance

print(datetimeInstance)

# Print the date instance

print(dateInstance)

Output

Output
2017-02-13 18:30:22.303811

2017-02-13