Skip to content

Instantly share code, notes, and snippets.

@garethrees
Created July 22, 2020 10:21
Show Gist options
  • Save garethrees/0af644830b81783f6f415db4698f8eff to your computer and use it in GitHub Desktop.
Save garethrees/0af644830b81783f6f415db4698f8eff to your computer and use it in GitHub Desktop.
Get date of each week start
def weeks_between(start_at, finish_at)
results = []
week_start = start_at.beginning_of_week
week_end = start_at.end_of_week
while week_end <= finish_at.end_of_week
# Collect these
results << [week_start, week_end]
# Update dates
week_start = week_end + 1.second
week_end = week_start.end_of_week
end
results
end
weeks = weeks_between(Time.parse('2020-08-03'), Time.parse('2021-12-31')).map(&:first).map(&:to_date).map(&:iso8601)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment