depassion
asked on
Calculate years and months from start and end dates
I have a rails employment management app Lets say a user creates a new work history entry. It contains a start and end date. How can i use ruby to calculate the number of months and years the user worked at that company? And also how to calculate the total years experience which is the sum of every work history.
eg work history 1
01-03-10 - 01-03-11
1 year
work history 2
01-03-11 - 01-03-12
1 year
total work experience 2 years
eg work history 1
01-03-10 - 01-03-11
1 year
work history 2
01-03-11 - 01-03-12
1 year
total work experience 2 years
#form
<% form_for [@user, @history] do |f| %>
<%= f.error_messages %>
<p>
<%= f.label :start %><br />
<%= f.date_select :start %>
</p>
<p>
<%= f.label :end %><br />
<%= f.date_select :end %>
</p>
<p>
<%= f.label :sector %><br />
<%= collection_select(:history, :sector_id, Sector.find(:all), :id, :name) %>
</p>
<p>
<%= f.label :company %><br />
<%= f.text_field :company, :size => 70 %>
</p>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.