import datetime

def first_day_of_next_month( year, month ):
   """returns the first day of the next month
   >>> first_day_of_next_month(2007,5)
   datetime.datetime(2007, 6, 1, 0, 0)
   >>> first_day_of_next_month(2007,12)
   datetime.datetime(2008, 1, 1, 0, 0)
   """
   oneday = datetime.timedelta(days=1)
   day = datetime.datetime(year, month, 1)
   if day.day == 1:
   day += oneday
   while day.day != 1:
       day += oneday
   return day


from time import mktime
def secondsInMonth(year, month):
   s1 = mktime((year,month,1,0,0,0,0,0,-1))
   day = first_day_of_next_month(year, month)
   year = day.year
   month = day.month
   s2 = mktime((year,month+1,1,0,0,0,0,0,-1))
   return s2-s1


year = 2007
month = 2
print secondsInMonth(year, month)





[EMAIL PROTECTED] wrote:
    Matt> from time import mktime
    Matt> def secondsInMonth(year, month):
    Matt>     s1 = mktime((year,month,1,0,0,0,0,0,-1))
    Matt>     s2 = mktime((year,month+1,1,0,0,0,0,0,-1))
    Matt>     return s2-s1

Probably won't work if month==12. ;-)

Skip

--
Shane Geiger
IT Director
National Council on Economic Education
[EMAIL PROTECTED]  |  402-438-8958  |  http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy

begin:vcard
fn:Shane Geiger
n:Geiger;Shane
org:National Council on Economic Education (NCEE)
adr:Suite 215;;201 N. 8th Street;Lincoln;NE;68508;United States
email;internet:[EMAIL PROTECTED]
title:IT Director
tel;work:402-438-8958
x-mozilla-html:FALSE
url:http://www.ncee.net
version:2.1
end:vcard

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to