ruby - How can I find the dates for the same week a year ago? -
this example of week, sunday saturday:
11/21/2010 - 11/27/2010
i find dates same week sunday-saturday, last year.
require 'date' # included in ruby's standard library, no gem needed = date.today before = date.civil( now.year-1, now.month, now.day ) sunday = date.commercial( before.year, before.cweek, 1 ) - 1 # day 1 monday this_week_last_year = sunday..(sunday+6)
edit: though date.commercial
cool, it's not needed. here's simpler way find sunday starting week:
require 'date' = date.today before = date.civil( now.year-1, now.month, now.day ) sunday = before - before.wday
Comments
Post a Comment