How can I calculate the difference between to dates in a form? The dates (day,Month,year) are in 3 different Drop-down boxes

StackOverflow https://stackoverflow.com/questions/16769696

سؤال

How can I calculate the difference between to dates in a form? The dates (day,Month,year) are in 3 different Drop-down boxes. So is it some how possible to get the value of the selected Drop-down which we define in the option tag?

هل كانت مفيدة؟

المحلول

You can do:

var dateA = new Date($("#yearA").val(), $("#monthA").val(), $("#dayA").val());
var dateB = new Date($("#yearB").val(), $("#monthB").val(), $("#dayB").val());
var diff = Math.abs(dateA - dateB);

Which will give you the difference between the two dates in milliseconds.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top