tags:

views:

99

answers:

1

guys i am having problems when trying to retrieve record from the database when the start_day and the end_day is equal, if i want to see the record of maybe: "from" 6 may 2009 To 6 may 2009. it doesn't give me the record and is there in the database it only give me the record if a type "From" 06 may 2009 To 7 may 2009. and my code is.

def generate_emails

@start = "#{params[:start][:day]}-#{params[:start][:month]}-#{params[:start][:year]}"
@start_date = Date.parse(@start) rescue
if !@start_date
  render :update do |page|
    page.hide "flash-error"
    page.visual_effect :highlight, "flash-error", :duration => 3
    page.replace_html "flash-error", "Invalid date, You selected #{params[:start][:day]} days for the #{params[:start][:month]} month"
    page.show "flash-error"
   end
  return
end

@end = "#{params[:end][:day]}-#{params[:end][:month]}-#{params[:end][:year]}"
@end_date = Date.parse(@end) rescue
  if !@end_date
  render :update do |page|
      page.hide "flash-error"
      page.visual_effect :highlight, "flash-error"
      page.replace_html "flash-error", "Invalid date, You selected #{params[:end][:day]} days for the #{params[:end][:month]} month"
      page.show "flash-error"
      end
  return
 end
@sent_message = SentMessage.find(:all, :conditions => ["message_type='Email' AND estate_id=? AND sent_date >= '#{@start_date}' AND sent_date <= '#{@end_date}' OR sent_date ='#{@start_date}' AND sent_date = '#{@end_date}' ", @estate_id], :order => "sent_date DESC")

end

please guys i need help!!.

atleast i got the answer..

def generate_emails

@start = "#{params[:start][:day]}-#{params[:start][:month]}-#{params[:start][:year]}"
@start_date = Date.parse(@start)rescue
if !@start_date
  render :update do |page|
    page.hide "flash-error"
    page.visual_effect :highlight, "flash-error", :duration => 3
    page.replace_html "flash-error", "Invalid date, You selected #{params[:start][:day]} days for the #{params[:start][:month]} month"
    page.show "flash-error"
   end
  return
end

@end = "#{params[:end][:day]}-#{params[:end][:month]}-#{params[:end][:year]}"
@end_date = Date.parse(@end) rescue
  if !@end_date
  render :update do |page|
      page.hide "flash-error"
      page.visual_effect :highlight, "flash-error"
      page.replace_html "flash-error", "Invalid date, You selected #{params[:end][:day]} days for the #{params[:end][:month]} month"
      page.show "flash-error"
      end
  return
 end

 if @start_date == @end_date
   @start_date = DateTime.parse(@start)-1
   @end_date = DateTime.parse(@end)
   @sent_message = SentMessage.find(:all, :conditions => ["message_type='Email' AND estate_id=? AND sent_date >= '#{@start_date}' AND sent_date = '#{@end_date}' ", @estate_id], :order => "sent_date DESC")
 end

@sent_message = SentMessage.find(:all, :conditions => ["message_type='Email' AND estate_id=? AND sent_date >= '#{@start_date}' AND sent_date <= '#{@end_date}' OR sent_date ='#{@start_date}' AND sent_date = '#{@end_date}' ", @estate_id], :order => "sent_date DESC")

end

A: 

I'd suggest you check whether the Date.parse is failing to parse @start and @end - odds are good that the values you're getting from the params cannot be parsed correctly by the locale of the application running the ruby code.

scraimer
Thanks guys but i came up with the answer, cause if you choose a day before the date that you want it gave you the answer..e.g "05 may 2009" to "06 may 2009".but that is not what the user is supposed to see,so i figured a method to subtract a day if they a equal..
Donald