2 Replies - 2226 Views - Last Post: 05 June 2012 - 06:36 AM Rate Topic: -----

#1 SanmanX  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 32
  • Joined: 11-January 12

getting data within date range

Posted 04 June 2012 - 12:29 PM

Hey guys i need help with my code. I'm trying to write a query where it finds all permits sold by a user within a date range. Here is what i have in my controller:

def report
	
 @performance_report = PerformanceReport.new(params[:performance_report])
    @users = User.find_by_spire_ID(params[:performance_report][:spire_ID])
		@permits = Permit.find_all_by_created_user_ID_and_date(@users.id, :start_date > :end_date )
 respond_to do |format|
	format.html #report.html.erb
  format.json {render json: @performance_report}
 end
end


I'm guessing that is not the right way to compare dates.

Is This A Good Question/Topic? 0
  • +

Replies To: getting data within date range

#2 Skaggles  Icon User is offline

  • THE PEN IS MIGHTIER
  • member icon





Reputation: 251
  • View blog
  • Posts: 640
  • Joined: 01-March 09

Re: getting data within date range

Posted 04 June 2012 - 02:36 PM

Try using a range of dates, such as:

@users = User.where(:creation_date => FIRST_DATE..END_DATE)

This post has been edited by Skaggles: 04 June 2012 - 02:37 PM

Was This Post Helpful? 1
  • +
  • -

#3 SanmanX  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 32
  • Joined: 11-January 12

Re: getting data within date range

Posted 05 June 2012 - 06:36 AM

Thx for the help but i figured it out from this place:
http://morecode.word...-ruby-on-rails/

So i just did:

@users = User.find_by_spire_ID(params[:performance_report][:spire_ID])
		@permits = Permit.find(:all, :conditions => {:created_user_ID => @users.id, :date_issued =>@performance_report.start_date..@performance_report.end_date}) 

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1