I am finding hard time figuring out a issue while trying to find records created this month.
my query in controller looks like this
@sh = SupportHistory.where('created_at BETWEEN ? AND ?', Time.now.beginning_of_month, DateTime.now.end_of_month)
my sql looks like this
SELECT `support_histories`.* FROM `support_histories` WHERE (created_at BETWEEN '2012-10-31 18:30:00' AND '2012-11-30 18:29:59')
The problem is its finding a record from previous month, how to fix it ?
Update
I was able to figure-out the problem through this link: Timezone with rails 3
Now my query in controller looks like this
@sh = SupportHistory.where('created_at BETWEEN ? AND ?', DateTime.now.in_time_zone.beginning_of_month, DateTime.now.in_time_zone.end_of_month)
Now my sql looks like this
SELECT `support_histories`.* FROM `support_histories` WHERE (created_at BETWEEN '2012-11-01 05:
00:00' AND '2012-12-01 05:59:59')
Now i have another Question, is there a way to avoid 'in_time_zone' ? or to make it happen automatically ? :)