Date format of datepicker

I try to calculate the difference of two dates with a date picker.

But I have a problem, it’s the fact that the format date is not good and I when I try to change it, the response of my result become false (I see NaN). And when my dates have the good format and my result become good, my datas don’t be save with my form.

I need someone to help me, thanks a lot.

function showDays()
{
    var start = $('.date_debut').datepicker('getDate');
    var end = $('.date_fin').datepicker('getDate');
    if (!start || !end) return;
    var days = (end - start) / 1000 / 60 / 60 / 24;
    days = days + 1;
    $('.date_debut').val(start);
    $('.date_fin').val(end);
    $('.resultat').val(days);
}
$('.date_debut').datepicker({ onSelect: showDays });
$('.date_fin').datepicker({ onSelect: showDays });

You can define the date format, if that helps:

http://api.jqueryui.com/datepicker/#option-dateFormat

Thanks for your reply.

I succeeded to change dateformat and the number of days was return in my browser console.

But the number of days was not return in my input (because I want to return in the value of a input).

I hope to have been clear.

Thank’s a lot

Nadir