Determining the number of days in a month
Here is a simple method that returns number of days for wanted month and year. If year is ommited current year is selected. def month_days(month, year=Date.today.year) mdays = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] mdays[2] = 29 if Date.leap?(year)mdays[month] end Simple examples: month_days(1) => 31 month_days(2, 2007) => [...]




Recent Comments