need Javascript to calculate day difference for dd-mm-yyyy hh:mm:ss(AM/PM)
-
hi i am using a javascript to calculate checkin checkout times of customer by using this script:
function calculate()
{
if(window.formSugam.txtunitcost.value!="" && window.formSugam.txtquantity.value !=""){
//-----------function for checking date and their validations
var ONE_DAY = 1000 * 60 * 60 * 24;
str1=new Array(6);
str2=new Array(6);
str1 = EnterDateInDDMMYY(window.formSugam.txtfromdate.value);
// EnterDateInDDMMYY method is to convert date into miliseconds
str2 = EnterDateInDDMMYY(window.formSugam.txttodate.value);
var date1=new Date(str1[0],str1[1],str1[2],str1[3],str1[4],str1[5]);
var date2=new Date(str2[0],str2[1],str2[2],str2[3],str2[4],str2[5]);
var datediff=date2-date1;
checkFloat(formSugam.txtunitcost)
checknumbervalue(formSugam.txtquantity)
val2=parseFloat(window.formSugam.txtunitcost.value );
val1=parseInt(window.formSugam.txtquantity.value );
dateval=parseInt(datediff);
val3=parseInt(Math.round(dateval/ONE_DAY));
if (val3==0)
{window.formSugam.txtbillamount.value=val1*val2;}
else{
window.formSugam.txtbillamount.value=val1*val2*val3;
}
//----------------hence it calculates date in round figure
}but the problem comes when i calculate a date diff for 31-10-2010 12:39:52PM to 01-11-2010 12:39:52PM else its working fine so what is the actual problem here in my code is related to month change,
-
hi i am using a javascript to calculate checkin checkout times of customer by using this script:
function calculate()
{
if(window.formSugam.txtunitcost.value!="" && window.formSugam.txtquantity.value !=""){
//-----------function for checking date and their validations
var ONE_DAY = 1000 * 60 * 60 * 24;
str1=new Array(6);
str2=new Array(6);
str1 = EnterDateInDDMMYY(window.formSugam.txtfromdate.value);
// EnterDateInDDMMYY method is to convert date into miliseconds
str2 = EnterDateInDDMMYY(window.formSugam.txttodate.value);
var date1=new Date(str1[0],str1[1],str1[2],str1[3],str1[4],str1[5]);
var date2=new Date(str2[0],str2[1],str2[2],str2[3],str2[4],str2[5]);
var datediff=date2-date1;
checkFloat(formSugam.txtunitcost)
checknumbervalue(formSugam.txtquantity)
val2=parseFloat(window.formSugam.txtunitcost.value );
val1=parseInt(window.formSugam.txtquantity.value );
dateval=parseInt(datediff);
val3=parseInt(Math.round(dateval/ONE_DAY));
if (val3==0)
{window.formSugam.txtbillamount.value=val1*val2;}
else{
window.formSugam.txtbillamount.value=val1*val2*val3;
}
//----------------hence it calculates date in round figure
}but the problem comes when i calculate a date diff for 31-10-2010 12:39:52PM to 01-11-2010 12:39:52PM else its working fine so what is the actual problem here in my code is related to month change,
Please visit following link http://stackoverflow.com/questions/1036742/date-difference-in-javascript-ignoring-time-of-day[^] Please provide "Vote":thumbsup: if this would be helpful, and make "Accept Answer" if this would be correct answer.:rose: Thanks, Imdadhusen
sunaSaRa Imdadhusen +91 99095 44184 +91 02767 284464