This mailing list for the discussion of development of core Rails features.
For support please consider using Stackoverflow, Quora, #RubyOnRails on IRC
or the rubyonrails-talk mailing list.
I sent you a reply off list.
-Al
On Thu, Aug 1, 2013 at 11:06 PM, <info@buzzflock.com> wrote:
> I have a Rails 3.2 app with an Article model that has a field for date. I
> want to create a scope that will retrieve all records from last month. The
> problem I''m having is that my current scope is not including the
first day
> of the month.
>
> # article.rb
> scope :last_month, lambda { { conditions: { date: last_month_range } } }
>
> private
> def self.last_month_range
> 1.month.ago.beginning_of_month..1.month.ago.end_of_month
> end
>
>
> When I run this it does this:
>
> SELECT * FROM ''articles'' WHERE
(''articles`.''date'' BETWEEN ''2013-07-01
> 07:00'' AND ''2013-08-01 06:59:59'')
> When I look at the actual results it only starts with the articles with a
> date of 07-02-2013.
>
>
> However, if I change the code to:
>
> def self.last_month_range
> (1.month.ago.beginning_of_month - 1.day)..1.month.ago.end_of_month
> end
>
>
> It does this:
>
> SELECT * FROM ''articles'' WHERE
(''articles`.''date'' BETWEEN ''2013-06-30
> 07:00'' AND ''2013-08-01 06:59:59'')
> In that case it pulls in articles with dates of 6/31/2013.
>
>
> Can someone please recommend a fix? Thank you!
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-core+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-core@googlegroups.com.
> Visit this group at http://groups.google.com/group/rubyonrails-core.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to rubyonrails-core+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/groups/opt_out.