From: Mohit Sindhwani Date: 2007-09-27T00:02:19+09:00 Subject: Re: Finding the last Sunday of a month Anyway, if you have: now = DateTime.now this_month = now.month this_budget_fencepost = \\\ based on what we discussed earlier /// then, you can find the budget fencepost for today using that.. If your budget posts are every 4 weeks from the last Sunday of January, you should be able to get the number of days since the first num_of_days = this_budget_fencepost - first_fencepost fencepost_number = num_of_days/ 28 You need to put in some check if the date is earlier than the first fencepost and check the numbers it actually produces, but roughly that should do it for you. Cheers, Mohit. 9/26/2007 | 10:59 PM. Peter Bailey wrote: > OK. Now, I've got that last Sunday's date in January. And, I've now > delineated all of the successive Sundays thereafter. Each of them is a > budgetary fencepost for me. So, can someone help me to determine what > budget period, out of all 13 of them, that today's date, or any day for > that matter, would fall into? I think that all of my budget dates below > are actually strings, so, they don't parse with dates as they are. > > Thanks, > Peter > > Here's what I have now. It works. I just need to see what today, or any > day, would fall into. > > require 'date' > now = DateTime.now > year = now.year > d = Date.new(now.year, 2, 1) > d.to_s > d -= 1 > d.to_s > d -= d.wday > i = d.wday > d.to_s > firstbudgetfence = d > > t = Time.now > t = t.strftime("%Y-%m-%d") > budget1 = Date.new(now.year, 1, 1) > budget2 = firstbudgetfence > budget3 = firstbudgetfence + 28 > budget4 = budget3 + 28 > budget5 = budget4 + 28 > budget6 = budget5 + 28 > budget7 = budget6 + 28 > budget8 = budget7 + 28 > budget9 = budget8 + 28 > budget10 = budget9 + 28 > budget11 = budget10 + 28 > budget12 = budget11 + 28 > budget13 = budget12 + 28 >