From: Daniel Berger Date: 2007-01-23T07:05:13+09:00 Subject: Re: find monday of first week of the month Daniel Liebig wrote: > Hi, > > im pretty new to Ruby and i tried to find out how to calculate the date > for the first monday of the first week of the month (i.e. this would be > 2007-01-29 for Feb. 2007) The first Monday in February is on January 29th? Hm, wait, I think I understand what you're trying to say. > My approach is to get the weekday of the first day of the month and > calculate back from there. By getting the weekday i can tell how far to > calculate back (if necessary at all). If i'm calcualating back from > janurary, i also have to switch back the year. > > So this is what i came out with: require 'date' date = Date.new(2007, 2) p date.strftime("%Y-%m-%d") # 2007-02-01 date -= 1 until date.mday == 1 p date.strftime("%Y-%m-%d") # 2007-01-29 Regards, Dan