From: Mohit Sindhwani Date: 2007-09-26T22:58:20+09:00 Subject: Re: Finding the last Sunday of a month Peter Bailey wrote: > Hello, > I need to find the date for the last Sunday in January, for any year. I > need this for a budgetary script I'm trying to write. Using the > Date/Time module, I've done this so far. > > require 'date' > now = DateTime.now > year = now.year > d = Date.new(now.year, 1, 31) > puts d.wday > > yields: 3 > The last Sunday of that month can be got this way, I think: require 'date' now = DateTime.now year = now.year d = Date.new(now.year, 1, 31) i = d.wday last_sunday = Date.new(now.year, 1, (31-i)) puts last_sunday The reference for dates is at: http://corelib.rubyonrails.org/classes/Date.html Cheers mohit.