Prev: Recommendations for a PostgreSQL driver for Ruby that supports bytea types correctly?
Next: algorithm to truncate date to beginning of week?
From: Chuck Remes on 9 Feb 2010 13:32 I need to be able to take any date after Jan 1, 1980 and truncate it to the nearest week. Example: Wed Jan 09 17:53:23 -0600 1980 should truncate to Sun Jan 06 00:00:00 -0600 1980 Tue Feb 09 12:29:51 -0600 2010 should truncate to Sun Feb 07 00:00:00 -0600 2010 I've tried all sorts of tricks with modulus (% operator) on the integer representation of time but I can't get anything to work over a range of dates. Anyone have any bright ideas? 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. cr |