javascript - Unexpected Response comparing Date Strings in Angular Controller -


i trying compare 2 date strings in angular controller getting unusual response. convert today's date string ("2/5/2016") , try compare string dates input. here code:

   function deletetablerows(table) {         var year = gettoday.getfullyear();         var month = gettoday.getmonth() + 1;         var day = gettoday.getdate();         var currentdate = month + "/" + day + "/" + year;         var qtr4 = '12/31/' + year;         var qtr3 = '9/30/' + year;         (var = table.length - 1; >= 0; i--) {             if (currentdate < qtr4) {                 if (table[i].intyear == year && table[i].intquarter == 4) {                     table.splice(i, 1);                 }             }             if (currentdate < qtr3) {                 if (table[i].intyear == year && table[i].intquarter == 3) {                     table.splice(i, 1);                 }             }         }  }; 

my issue when compares currentdate('2/5/2016') qtr4('12/31/2016') evaluates if statement false meaning, 2/5/2016 not less 12/31/2016. however, evaluates 2nd if state true meaning, currentdate('2/5/2016') less qtr3('9/30/2016'). not understand behavior, suspect there simple missing here. assistance appreciated!

you should compare date using gettime() like: yourdate.gettime() , convert string date before use it.

var currentdate = new date(month + "/" + day + "/" + year); var qtr4 = new date('12/31/' + year); var qtr3 = new date('9/30/' + year); 

and compare like

if( currentdate.gettime() < qtr3.gettime() ) 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -