Attributes Of Datetime Class In Python

The datetime class has several attributes pertaining to date, time and timezone information. Here is the list of class attributes and instance attributes:

 

Class attributes of Python datetime class

min

 

A date time instance representing the date 01Jan01-00:00:00  - the minimum Gregorian proleptic Date.

max

 

The maximum Gregorian date which is 31Dec9999-24:59:59-999999.

resolution

 

  • The smallest time difference between two unequal datetime objects i.e., 1 Microsecond.
  • Note that, the minimum resolution between two date objects is 1 day. But, when it comes to the minimum resolution between two datetime objects it is 1 microsecond.
  • The reason is the minimum quantity that can be represented in a datetime object is 1 microsecond whereas in a date object it is 1 day.

 

Instance attributes of Python datetime class

year

Valid values for the year are from 1 to 9999.

month

Valid values for the month are from 1 to 12.

day

Valid values for the day are as per the number of days for that specific month as calculated by the Gregorian Calendar.

hour

Valid values for hour are from 0 to 23.

minute

Valid values for minute are from 0 to 59.

second

Valid values for second are from 0 to 59.

microsecond

Valid values for microsecond are from 0 to 999999.

tzinfo

An instance of a class derived from tzinfo, which provides time zone information.

fold

  • The fold attribute is a flag.
  • It represents a fold in time.
  • A fold in time happens when a clock is reset to the same time after the elapse of finite time duration.
  • Example for fold in time: In countries following day light saving time, at the end of summer the clocks are reset back by 1 hour, which creates

a fold in time for the length of 1 hour. The Theflagtells whether at least one fold has happened. For countries that do not follow daylight saving time should be zero.

 


Copyright 2023 © pythontic.com