How to find out if february has 29 or 28 days ?
Steve Holden
sholden at holdenweb.com
Fri Aug 2 13:39:26 EDT 2002
"John Hunter" <jdhunter at ace.bsd.uchicago.edu> wrote in message
news:mailman.1028042640.11642.python-list at python.org...
> >>>>> "Marcus" == Marcus Vinicius Laranjeira
<m.laranjeira at datacraft.com.br> writes:
>
> Marcus> I use the mx.DateTime package, and I need to know if in
> Marcus> one particular year has a february with 28 or 29 days ? I
> Marcus> don't know how to do that !
>
>
> Here's one way....
>
> import mx.DateTime
>
> def is_leapyear(year):
> try:
> d = mx.DateTime.DateTime(year,2,29)
> return 1
> except mx.DateTime.mxDateTime.RangeError:
> return 0
>
> print is_leapyear(2000)
> print is_leapyear(2002)
>
Another way is to RTFM :-) From the mx.DateTime documentation on DateTime
instance variables:
is_leapyear
Returns 1 iff the instances value points to a leap year in the Gregorian
calendar.
regards
-----------------------------------------------------------------------
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------
More information about the Python-list
mailing list