Python Method

Python Method

  1. Syntax of Python Method
  2. Example Code: Use the Method in Python

The datetime module is a robust module available in Python. It deals with dates, times, and time zones and offers reliable utilities and solutions.

This module implements a class datetime that stores date along with time and timezone. This class has various instance methods, being one that returns a date object for the exact date.

Syntax of Python Method

<datetime object>.date()


This method does not accept any parameters.


This method returns a date object for the datetime object date. The date class is a part of the datetime module.

It accepts three arguments, namely, year, month, and day and it offers various methods to work with the object. To learn about the class, refer to the official Python documentation here.

Example Code: Use the Method in Python

from datetime import datetime

dt =
print("DateTime object:", dt)
date =
print("Date object:", date)


DateTime object: 2022-08-23 12:22:02.813862
<class 'datetime.datetime'>
Date object: 2022-08-23
<class ''>

The Python code above first creates a datetime object using the now() method that, as the name suggests, returns a datetime instance for the current moment. Next, we extract a date object from it with the help of the date() method.

The outputs prove that the former is a datetime object and the latter is a date object, which refers to the exact moment or day.

Vaibhav Vaibhav avatar Vaibhav Vaibhav avatar

Vaibhav is an artificial intelligence and cloud computing stan. He likes to build end-to-end full-stack web and mobile applications. Besides computer science and technology, he loves playing cricket and badminton, going on bike rides, and doodling.

LinkedIn GitHub

Related Article - Python Datetime

  • Python Method
  • Python Method
  • Python Method
  • Python datetime.datetime.timetuple() Method
  • Python datetime.time.replace() Method
  • Python datetime.time.time.strftime() Method