Ok,
the problem here I think is not so much that you’re using the Date/Calendar Widget but the fact that you’re doing a calculation on the client.
Internally (on the server) Bonita will be using date and time as date and time, what you are trying to do is use the browsers representation, according to your locale settings. I understood this when you gave your example…
“20. November 2014”
this is your browsers “German locale” version of the date, which on my English system just shows
“20 November 2014”
Because you are using JavaScript on the form data (which is basic HTML), then you will have to convert it to a date format first before doing any calculations…JavaScript Date is quite flexible…
try this…from here
var d = new Date(dateString);
or unpackage the date using subString etc. using
var d = new Date(year, month, day, hours, minutes, seconds, milliseconds);
In - fact try it out here …it works…change the date on the left to your exact format (20. November 2014) and then click the button and you will see JavaScipt honor the format, then you can do your calculations on var d.
You calculation simply needs to be here is a full set of function code:
function DaysDifference( date1, date2 ) {
var d1 = new date(date1);
var d2 = new date(date2);
//Get 1 day in milliseconds
var one_day=10006060*24;
// Convert both dates to milliseconds
var date1_ms = d1.getTime();
var date2_ms = d2.getTime();
// Calculate the difference in milliseconds
var difference_ms = date2_ms - date1_ms;
// Convert back to days and return
return Math.round(difference_ms/one_day);
}
var noOfDays = DaysDifference(“20. November 2014”, “25. November 2014”);
best regards
Sean