check if one date is between two dates (javascript) -
i need 1 thing, need check if 1 date, string in fomat dd/mm/yyyy contained between 2 dates, same format (dd/mm/yyyy)
i tried this, doesn't work:
var datefrom = "02/05/2013"; var dateto = "02/09/2013"; var datecheck = "02/07/2013"; var = date.parse(datefrom); var = date.parse(dateto); var check = date.parse(datecheck ); if((check <= && check >= from)) alert("date contained");
i used debugger , check,to , variables have isnan value me, please? best regards, daniel
date.parse
supports format mm/dd/yyyy not dd/mm/yyyy. either have use library moment.js or given below
var datefrom = "02/05/2013"; var dateto = "02/09/2013"; var datecheck = "02/07/2013"; var d1 = datefrom.split("/"); var d2 = dateto.split("/"); var c = datecheck.split("/"); var = new date(d1[2], parseint(d1[1])-1, d1[0]); // -1 because months 0 11 var = new date(d2[2], parseint(d2[1])-1, d2[0]); var check = new date(c[2], parseint(c[1])-1, c[0]); console.log(check > && check < to)
Comments
Post a Comment