Date Calculations

Fredrik Lundh fredrik at
Mon Aug 23 09:00:34 EDT 1999

Per Kistler <kistler at> wrote:
> I'm making some Date Calculaton class with things like
> deltaDays, addDays, daysInYear and so on, above the calendar 
> and time classes. After some 300 lines I thought, I better
> ask, whether that has already been done by someone else.

in addition to the other modules mentioned in this
thread, there's also something called:


in the standard distribution. here's the 'abstract':

# Date(month,day,year) returns a Date object.  An instance prints as,
# e.g., 'Mon 16 Aug 1993'.
# Addition, subtraction, comparison operators, min, max, and sorting
# all work as expected for date objects:  int+date or date+int returns
# the date `int' days from `date'; date+date raises an exception;
# date-int returns the date `int' days before `date'; date2-date1 returns
# an integer, the number of days from date1 to date2; int-date raises an
# exception; date1 < date2 is true iff date1 occurs before date2 (&
# similarly for other comparisons); min(date1,date2) is the earlier of
# the two dates and max(date1,date2) the later; and date objects can be
# used as dictionary keys.
# Date objects support one visible method, date.weekday().  This returns
# the day of the week the date falls on, as a string.
# Date objects also have 4 read-only data attributes:
#   .month  in 1..12
#   .day    in 1..31
#   .year   int or long int
#   .ord    the ordinal of the date relative to an arbitrary staring point
# The Dates module also supplies function today(), which returns the
# current date as a date object.

(it's written by timbot, btw).


More information about the Python-list mailing list