Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Quote:
consloe show NAN


What I have tried:

JavaScript
if(fromDate && toDate){
				var totalDate = (toDate - fromDate) / (1000 * 60 * 60 * 24);
			console.log(totalDate)
			}
Posted
Updated 4-Jul-18 1:04am
v2
Comments
F-ES Sitecore 4-Jul-18 6:05am    
You use "toDate" in the "if" but "totDay" in the equation, is that a typo? If not what is fromDate, toDate and totDay? Where do they come form and what is their contents?

1 solution

If you are getting the date from DatePicker, then try the below:

var fromDate = $('#date1').datepicker('getDate');
var toDate = $('#date2').datepicker('getDate');
var diff = 0;
      
if (fromDate && toDate) {
    diff = Math.floor((toDate.getTime() - fromDate.getTime()) / 86400000); // ms per day
}

console.log(diff);
 
Share this answer
 
Comments
Maung C 4-Jul-18 23:30pm    
I'm using datetimepicker not datepicker, so it's can't fix. thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900