From: Dan Fitzpatrick Date: 2008-02-28T04:50:44+09:00 Subject: Re: Getting number of days in a month Shandy Nantz wrote: > This is probably an easy question but I am trying to get at the number > of days that are in a month. I have this calendar that I have built, the > idea being that when a month turns from February to March, for example, > the calendar should redisplay itself properly formated showing the new > month and the correct number of days. I have it so that it starts > counting the days on the right day of the week, but I have to know when > to stop counting. Any ideas, Thanks, > > -S > If you don't want to use the Date module, this is the plain old way: def days_in_month(m=Time.new.month,y=Time.new.year) return [31,0,31,30,31,30,31,31,30,31,30,31][m-1] unless m == 2 ((y % 4 == 0) and ( (!(y % 100 == 0)) or (y % 400 == 0) ) ) ? 29 : 28 end Dan