Kalyani Shevale

Kalyani Shevale

  • NA
  • 3.2k
  • 711.5k

how get Two date Diff in jquery

Jul 5 2019 4:31 AM
 I have Used two date using datepicker .how to calculate date difference in jquery.
 
I have applied blow code but in that, the code I want 3 days to count using the form to date that time count will be 2 displayed. 
 
  1. @Html.TextBoxFor(m => m.fromDate, new { @class = "form-control", @placeholder = "From Date", @id = "fromDate"})  
  2.   @Html.TextBoxFor(m => m.toDate, new { @class = "form-control",  @placeholder = "To Date", @id = "toDate"})  
  3.   
  4.   
  5.   
  6. $("#fromDate").datepicker({  
  7.              
  8.             minDate: 0,  
  9.             maxDate: '+0Y+1M',  
  10.               
  11.             onSelect: function (dateStr) {  
  12.                 var min = $(this).val();  
  13.             }  
  14.         });  
  15.   
  16.         $("#toDate").datepicker({  
  17.         
  18.             minDate: '0',  
  19.             maxDate: '+0Y+1M',  
  20.             onSelect: function (dateStr) {  
  21.                 debugger;  
  22.                 var max = $(this).val(); // Get selected date  
  23.               
  24.                 var start = $("#fromDate").val();  
  25.                 var end = $("#toDate").val();  
  26.                
  27.                 var days = Math.round(Math.abs((new Date(end) - new Date(start)) / (1000 * 60 * 60 * 24)));  
  28.                 $("#TextBox3").val(Math.round(days));  
  29.             }  
  30.         });  
 please help
 
 
I want data that like..
01/07/2019 TO 03/07/2019   Totals days =3 

Answers (2)