From: Chuck Remes Date: 2010-02-10T04:21:34+09:00 Subject: Re: algorithm to truncate date to beginning of week? On Feb 9, 2010, at 12:58 PM, Yossef Mendelssohn wrote: > On Feb 9, 12:32 pm, Chuck Remes wrote: >> My end goal is to always be able to pick the first Sunday at midnight backwards from a given date. If there is another approach to accomplish this, please share. > > Use the logic inherent in Date objects. They can tell you the weekday > (as an integer, 0-based starting at Sunday), and subtraction/addition > work on days. > > $ irb -rdate >>> d = Date.today > => # >>> d.to_s > => "2010-02-09" >>> d-d.wday > => # >>> _.to_s > => "2010-02-07" Ah! Date#wday is what I needed! I do need Time objects but it's easy (as you pointed out) to convert between them. Thanks for your insight. cr