The Wayback Machine - https://web.archive.org/web/20200505133133/https://www.geeksforgeeks.org/python-datetime-module-with-examples/amp/

Python datetime module with examples

In Python, date and time are not a data type of its own, but a module named datetime can be imported to work with the date as well as time. Datetime module comes built into Python, so there is no need to install it externally.

Datetime module supplies classes to work with date and time. These classes provide a number of functions to deal with dates, times and time intervals. Date and datetime are an object in Python, so when you manipulate them, you are actually manipulating objects and not string or timestamps.

The datetime classes are categorize into 6 main classes –



Date class

When an object of this class is instantiated, it represents a date in the format YYYY-MM-DD. Constructor of this class needs three mandatory arguments year, month and date.

Constructor syntax:

class datetime.date(year, month, day)

The arguments must be in the following range –

Article Tags :