I have two strings in mm-yyyy format (eg: 05-2012) and I need to compare them.
I tried using $filter
and Date.parse
, but no luck thus far. I don't want to append the string with a dummy 'day' part, unless there is no other way.
Below is my code. Any help would be much appreciated. Thanks.
var date1= $filter('text')($scope.date1, "mm-yyyy");
var date2= $filter('text')($scope.date2, "mm-yyyy");
if (date2 <= date1) {
$scope.hasInvalidDate = true;
}
<input type="text" ng-model="date1" placeholder="mm-yyyy">
<input type="text" ng-model="date2" placeholder="mm-yyyy">