views:

502

answers:

1

HI Guys,

I have 2 asp.net texboxes with calendar extender. i want to find out the number of days between both dates when one of the date control is changed. how can i achieve this using jquery or javascript ?

+1  A: 

This should do the trick

var start = $('#start_date').val();
var end = $('#end_date').val();

// end - start returns difference in milliseconds 
var diff = new Date(end - start);

// get days
var days = diff/1000/60/60/24;

Example

var start = new Date("2010-04-01");
var end = new Date();
var diff = new Date(end - start);
var days = diff/1000/60/60/24

days //=> 8.525845775462964
macek