Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
JavaScript
<script type="text/javascript" src="js/jquery.ui.datepicker-tr.js"> </script>
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/jquery.flexslider-min.js"></script>

<script type="text/javascript" src="js/calendar1.js"></script>
<script type="text/javascript" src="js/Calendar2.js"></script>

<script type="text/javascript">
$(function () {
  $("#<%= TextBox1.ClientID %>").datepicker({ minDate: 0, maxDate: '+1Y+6M', onSelect: function (dateStr) {
    var min = $(this).datepicker('getDate'); // Get selected date
    $("#<%= TextBox2.ClientID %>").datepicker('option', 'minDate', min || '0'); // Set other min, default to today
  }});

  $("#<%= TextBox2.ClientID %>").datepicker({ minDate: '0', maxDate: '+1Y+6M', onSelect: function (dateStr) {
    var max = $(this).datepicker('getDate'); // Get selected date
    $('#datepicker').datepicker('option', 'maxDate', max || '+1Y+6M'); // Set other max, default to +18 months
    var start = $("#<%= TextBox1.ClientID %>").get();
    var end = $("#<%= TextBox2.ClientID %>").get();
    var diff = new Date(end - start);
    var days =Math.abs( diff / (1000 * 60 * 60 * 24));
    $("#<%= TextBox3.ClientID %>").val(days);
  }});
});
</script>
Posted
Updated 10-Aug-14 6:09am
v4
Comments
[no name] 10-Aug-14 8:16am    
Looks more like javascript than C# to me. Not sure what it is that you would expect from dividing a Date object by an integer value would get you. See,
http://www.htmlgoodies.com/html5/javascript/calculating-the-difference-between-two-dates-in-javascript.html#fbid=AWychY-QSqg
Debug and see where exactly you are getting the NAN error?
Kornfeld Eliyahu Peter 10-Aug-14 8:40am    
I believe here: var days = Math.abs( diff / (1000 * 60 * 60 * 24));
diff is a JavaScipt Date object!
See my answer. :)
Monika Rangta 10-Aug-14 8:48am    
Well, I am new in javascript...
in TextBox3, it is showing NaN ..I think, There is problem in calculation.

I changed the code a little bit and now it is working.
JavaScript
var start = $("#TextBox1").datepicker("getDate");
var end = $("#TextBox2").datepicker("getDate");
var days = (end - start) / (1000 * 60 * 60 * 24);

Demo


[Demo] Calculate Day Difference by jQuery Datepicker[^]
 
Share this answer
 
Comments
Monika Rangta 10-Aug-14 9:10am    
Thanks alot.. Its Working grt :)
Most welcome. Please accept the answer and upvote. :)
The variable diff is a Date so you cannot divide it by a number. you need to use one of the getters to extract a time value, such as:
JavaScript
var days =Math.abs( diff.getMilliseconds() / (1000 * 60 * 60 * 24));
 
Share this answer
 
Comments
Monika Rangta 10-Aug-14 9:10am    
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