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