script for seconds in given month?

Alex Martelli aleax at mac.com
Tue Apr 17 00:41:00 EDT 2007


edfialk <edfialk at gmail.com> wrote:

> Hi, does anyone happen to know of a script that would return the
> number of seconds in a month if I give it a month and a year?
> 
> My python is a little weak, but if anyone could offer some suggestions
> I think I could handle it myself, or if anyone happens to know of a
> script already written that performs this I would be extremely
> grateful.

import calendar

def seconds_in_month(month, year):
    nomatter, daysinmonth = calendar.monthrange(year, month)
    return daysinmonth * 24 * 60 * 60


Alex



More information about the Python-list mailing list