How to check if a Month/Year is greater than current Month/Year in Javascript
javascript
Solution
`Date` objects can be compared with each other. So instead of parsing them you can do it as `date` object itself.
function isDateGreaterThanToday(b) {
var dS = b.split("/");
var d1 = new Date(dS[1], (+dS[0] - 1));
var today = new Date();
if (d1 > today) {
return "D is greater";
} else {
return "today is greater";
}
}
console.log(isDateGreaterThanToday("08/2014"))
JSFiddle
Problem
I want to check if 08/2014 is greater than 02/2014.. How can I do that in Javascript?? Could someone help me please... Currently I only check for future year. Here is the code snippet. ``` this.isDateGreaterThanCurrent=function(b){ return parseInt(b)>parseInt(new Date().getFullYear()); }; ```