i have 3 text fields in rails view
<div>
<%= f.label :from_date %>
<%= f.text_field :start_date, :class => 'datepicker' %>
</div>
<div>
<%= f.label :to_date %>
<%= f.text_field :end_date, :class => 'datepicker' %>
</div>
<div>
<label>Days</label
<%= f.text_field :days,:readonly => true %>
</div>
by selecting dates from pickadate. mt code in application.js is :
$('.datepicker).pickadate();
i want to calculate the days between dates. my calculate method is defined below:-
function calculate() {
var d1 = $('#startdate').pickadate('getDate');
var d2 = $('#enddate').pickadate('getDate');
var diff = 1;
if (d1 && d2) {
diff = diff + Math.floor((d2.getTime() - d1.getTime()) / 86400000);
}
$('#days').val(diff);
}
but it does not work properly there is something missing. i didn't get it. please help me. Thanks in advance.