Skip to content

Instantly share code, notes, and snippets.

@danhodge
Created August 4, 2014 14:23
Show Gist options
  • Save danhodge/f77afbfab4cd6a746bc3 to your computer and use it in GitHub Desktop.
Save danhodge/f77afbfab4cd6a746bc3 to your computer and use it in GitHub Desktop.
Common date ranges using Active Support's date calculations
# require 'active_support'
# Monday, August 3, 2014
today = Date.today #=> Mon, 04 Aug 2014
Date.yesterday #=> Sun, 03 Aug 2014
Date.tomorrow #=> Tue, 05 Aug 2014
# this week
today.beginning_of_week #=> Mon, 04 Aug 2014
today.end_of_week #=> Sun, 10 Aug 2014
# last week
today.prev_week.beginning_of_week #=> Mon, 28 Jul 2014
today.prev_week.end_of_week #=> Sun, 03 Aug 2014
# this month
today.beginning_of_month #=> Fri, 01 Aug 2014
today.end_of_month #=> Sun, 31 Aug 2014
# last month
today.last_month.beginning_of_month #=> Tue, 01 Jul 2014
today.last_month.end_of_month #=> Thu, 31 Jul 2014
# 3 months ago
today - 3.months #=> Sun, 04 May 2014
# this quarter
today.beginning_of_quarter #=> Tue, 01 Jul 2014
today.end_of_quarter #=> Tue, 30 Sep 2014
# last quarter
today.prev_quarter.beginning_of_quarter #=> Tue, 01 Apr 2014
today.prev_quarter.end_of_quarter #=> Mon, 30 Jun 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment