Records monthwise ?

Hi Champs, I hope this is not a newbie question.:slight_smile:

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.

Hi Champs, I hope this is not a newbie question.:slight_smile:

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.

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.