Hi Champs, I hope this is not a newbie question.:) I have an leave table with columns start_date and end_date. Employees can apply leave for any date. Now i want to display the number of days of leave he had taken in a year.. I want it to be displayed like this:- Jan - 1 Feb - 10 Mar - 11 .. .. Dec - 12 Total - Whatever Can you guys suggest me some way? Thanks in advance. -- Posted via ruby-forum.com. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en.
> Hi Champs, I hope this is not a newbie question.:)Its not as bad as last time, but you may still get yelled at, especially since you''re posting on a monday Leave.sum("DAY(end_date) - DAY(start_date) + 1", :group => "MONTH(start_date)", :conditions => ["YEAR(start_date)=?",the_year_you_want]) This query will work, but requires that you handle leaves that begins in one month and ends in another by creating one record for each month. This could create new problems because that means you can no longer sum the number of leaves in a given period by simply counting the number of records. -- Posted via ruby-forum.com. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en.
Sharagoz -- wrote: I think i am just near to resolve it.. Got the logic to it.. I''ll tell you how i am doing it. ----------- @month_leaves = Array.new for i in 1..12 month = i year = Date.today.year start_date = Date.parse("#{year}-#{month}-01") end_date = start_date + 1.month @month_leaves << Leaves.find(:all, :conditions => [ "employee_id = ? and start_date >= ? and end_date < ?", session[:employee].id, start_date, end_date ]) ------------ Now two confusions:- 1) Am i assigning the value correct to array.. This is correct way .. Rit .. Also tried with @month_leaves[i] .. But cant get it to the views page.. 2) How can we give the different names in a loop.. I mean i do not want this @month_leaves alone handle this situations. But it should be like .. @month_1, @month_2 etc etc ..>> Hi Champs, I hope this is not a newbie question.:) > Its not as bad as last time, but you may still get yelled at, especially > since you''re posting on a monday > > > Leave.sum("DAY(end_date) - DAY(start_date) + 1", :group => > "MONTH(start_date)", :conditions => > ["YEAR(start_date)=?",the_year_you_want]) > > This query will work, but requires that you handle leaves that begins in > one month and ends in another by creating one record for each month. > This could create new problems because that means you can no longer sum > the number of leaves in a given period by simply counting the number of > records.-- Posted via ruby-forum.com. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en.