javascript - Calculating Date difference and matching it with array -


is there way in javascript can check if date between 2 dates?

i have array like

var unavailabledates = ["5-7-2011","6-7-2011","7-7-2011","15-7-2011","16-7-2011","17-7-2011" ]; 

and have 2 dates 1-7-2011 , 10-7-2011. want see if value unavailabledates falls between these date. if falls should return alert.

can me on this? in process of learning more javascript , jquery. not able code way understood problem.

here have solution

var unavailabledates = ["5-7-2011","6-7-2011","7-7-2011","15-7-2011","16-7-2011","17-7-2011" ]; function str2date(sdate){ //this function gets string , return date object    var parts = sdate.split("-");    return new date(parts[2], parseint(parts[1], 10)-1, parts[0]); } var stamp1 = str2date("1-7-2011").gettime(); //first date. gettime() converts integer var stamp2 = str2date("10-7-2011").gettime(); //second date for(var i=0; i<unavailabledates.length; i++){    var curstamp = str2date(unavailabledates[i]).gettime();    if(curstamp >= stamp1 && curstamp <= stamp2) //check if falls in range        alert(unavailabledates[i] + " falls in range"); } 

hope helps. cheers


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -