Forum: Ruby on Rails Find Current Month ?

Posted by Maddy (Guest)
on 2013-01-24 13:25
(Received via mailing list)
HI Folks,

How to find current month?
and
How to collect current month data from our database?

Please advice.

Thank You.
Posted by Jordon Bedwell (Guest)
on 2013-01-24 13:33
(Received via mailing list)
On Thu, Jan 24, 2013 at 6:24 AM, Maddy <ashokkumar@shriramits.com> 
wrote:
> How to find current month?
> and
> How to collect current month data from our database?

I'm not trying to be a dick, but these are fundamental tasks that you
should have learned first.

[1] pry(main)> Time.new.strftime("%B") #=> "January"
[2] pry(main)> Time.new.strftime("%b") #=> "Jan"
[3] pry(main)> Time.new.month #=> 1

As for the latter, that's a hard question to ask, because I would not
query by date the Rails way, I would opt to use PG functions to format
the date and query that way so without knowing a database I cannot
help there but it's not hard to use where("created_at >= ?",
5.days.ago) though I don't even know if that's a good way to do it in
Rails because again I would never do date queries directly in Rails.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.