dateutils Homepage - http://www.voidspace.org.uk/atlantibots/pythonutils.html There are various useful 'constants' defined in dateutils : monthslower, dayslower = lowercase lists of the days and months monthdict, monthdictleap = dictionaries keyed by month - value is the number of days in the month (monthdictleap is for a leap year) monthlist, monthlistleap = a list of the number of days in the month (monthlistleap is for a leapyear) days, months = capitalised lists of the days and months dateformcon = a dictionary with the standard config settings for the formatted date function. The Following functions are defined in dateutils : realdate(day, month, year) Returns true if the supplied date is a possible date and False if it isn't :-) (Note - it only tests that the *year* is greater than zero). isleapyear(year) Given a year as an integer (e.g. 2004) it returns True if the year is a leap year, and False if it isn't. daysinmonth(year, month) Given a year and a month it returns how many days are in that month. datetoday(day, month, year) Passed in a date, in integers, it returns the day of the week. Output is expressed as an integer from 0-6. 0 is Sunday, 1 is Monday....... datestringtoints(datestring) Passed in a datestring - in the form 'yyyymmdd' (e.g. 20040122 being 22nd January 2004) - it returns an integer tuple ( yyyy, mm, dd ). If the datestring is of the wrong length it returns None. (It assumes a four figure year). intstodatestring(day, month, year) Given three integers for day, month and year it returns a datestring 'yyyymmdd' (for easy storage). returndate() Returns the local date using the localtime function from the time module. Returns integers - ( yyyy, mm, dd ). nearestday(day, month, year, dayofweek = 2, afteronly = 0) Given a date as three integers (year, month and day) it returns the nearest date that is 'dayofweek'. (dayofweek should be an integer from 0 - 6. 0 is Sunday, 1 Monday etc..) If afteronly is set to 1 then it finds the nearest date of that day, on or *after* the specified. Returns integers - ( yyyy, mm, dd ). dayofweek defaults to Tuesday (2) and afteronly defaults to 0 as they are the defaults I'm using for the Victory Day program this is written for. This is used for : e.g find the nearest Tuesday to a given date, or find the nearest Tuesday *after* a given date ! addnumdays(day, month, year, modifier) Given a date as three integers (year, month and day) and a number of days to add or subtract to that date (the integer modifier, positive or negative value) - it returns the correct date as a tuple of integers - ( yyyy, mm, dd ). incdate(day, month, year) Given a date it adds one day to the date and returns the new date. decdate(day, month, year) Given a date it subtracts one day from the date and returns the new date. adddate(day1, month1, year1, day2, month2, year2) Given a date as three integers (year1, month1 and day1) and another number of days (day2), months (month2) and years (year2) to add to that date (or subtract from it) - it returns the new date as a tuple of integers - ( yyyy, mm, dd ). Note : Feb 28th + 1 month = March 31st Feb 29th + 1 month = March 31st January 29th to 31st + 1 month = feb 28th/29th August 31st + 1 month = September 30th We add the years together, then the months, then correct for the 'end of month' (e.g. we change Sep 31st to Sep 30th) Finally we add any extra days on. daycount(year, month, day) This is an implementation of the Julian Day system. This is a continuous count of days from January 1, 4713 B.C. Given a date in in integers it returns an integer value for the date This represents it's Julian Day number as above. This only works for dates represented using the the Gregorian calendar which was adopted in the US/UK on Oct. 15, 1582 - but at different times elsewhere (so historical dates may not be in this system....). counttodate(daycount) Given the number for a date using the Julian Day System, it returns that date as integer tuple (year, month, day). daysbetween(day1, month1, year1, day2, month2, year2) Given two dates it returns the number of days between them. If date1 is earlier than date2 then the result will be positive. dayfinish(day) Takes an integer day and returns the correct finish for it 1 = 'st', 2 = 'nd', 3 = 'rd', 4-10 = 'th' etc.... formatteddate(day, month, year, configdict = {}, **configs) Given a date in in integers, it returns the date as a nicely formatted string : e.g. 24th January 1997 or 2nd February 1948 configs accepts the following keywords : dayofweek, addzero, addcom, fullstop, monthfirst e.g. print formatteddate(12, 8, 1974, dayofweek=1, addzero=0, addcom=1, fullstop=1, monthfirst=0) Monday 12th August, 1974. If dayofweek is set to 1 then the day of the week will also be printed : e.g. Monday 24th January 1997 If addzero is set to 1 then days 1-9 will have an additional zero : e.g. 02nd February 1948 If addcom is set to 1 then there will be a comma between the month and the year : e.g. 24th January, 1997 If fullstop is set to 1 then there will be a fullstop after the year : e.g. 24th January 1997. If monthfirst is set to 1 then then the month will be put before the day : e.g. January 24th 1997 If the year is set to zero then it will be missed off. (and the dayofweek will be treated as 0 in this case as well). There is a dictionary called dateformcon defined in the dateutils module with all the config values defined and some good standard settings :-) This dictionary can be passed in instead of the individual settings.