You can easily modify the date format to yyyy/MM/dd
and everything should work smoothly.
// Custom code block
angular.module("app",[]).controller('ctrl',function($scope){
$scope.startDate = '/Date(1441045800000)/';
$scope.mfstDate = new Date(2015,8,1);
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
<h1>Hello Plunker!</h1>
{{startDate.slice(6,-2) | date:'dd/MM/yyyy'}}
<div ng-if="(mfstDate| date:'yyyy/MM/dd')>(startDate.slice(6,-2) | date:'yyyy/MM/dd')" style="background-color:#E25D5D">{{startDate.slice(6,-2) | date:'dd/MM/yyyy'}} less {{mfstDate| date:'dd/MM/yyyy'}}</div>
<div ng-if="(mfstDate| date:'yyyy/MM/dd')<(startDate.slice(6,-2) | date:'yyyy/MM/dd')" style="background-color:#E25D5D">{{startDate.slice(6,-2) | date:'dd/MM/yyyy'}} greater {{mfstDate| date:'dd/MM/yyyy'}}</div>
</div>
UPDATE it appears that you just need to make a small adjustment in your getFirst_Last_DateOfMonth
function. There is no need to manually format the string since Angular provides a useful filter called date
which you are already using within the view.
Simply return the date instead of a string,
function getFirst_Last_DateOfMonth(F_L) {
//here F=First Date of Current month
// L=Last Date of Current Month
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth();
var yyyy = today.getFullYear();
var firstLastDay = F_L == 'F'? new Date(yyyy,mm,1) : new Date(yyyy, mm + 1, 0);
return firstLastDay; //return Date object and in view use date filter when need comaring
//return $filter('date')(firstLastDay,'yyyy/MM/dd'); //uncomment if want return formatted string
}
Check out the updated snippet below
// Modified code block
angular.module("app", []).controller('ctrl', function($scope, $filter) {
function getFirst_Last_DateOfMonth(F_L, formatString) {
//here F=First Date of Current month
// L=Last Date of Current Month
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth();
var yyyy = today.getFullYear();
var firstLastDay = F_L == 'F' ? new Date(yyyy, mm, 1) : new Date(yyyy, mm + 1, 0);
return !formatString ? firstLastDay //return Date object and in view use date filter when need comaring
: $filter('date')(firstLastDay, 'yyyy/MM/dd'); //uncomment if want return formatted string
}
$scope.startDate = '/Date(1441045800000)/';
$scope.mfstDate = getFirst_Last_DateOfMonth('F');
$scope.mfstDateString = getFirst_Last_DateOfMonth('F', true);
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
<h1>Hello Plunker!</h1>
{{startDate.slice(6,-2) | date:'dd/MM/yyyy'}}
<div>
mfstDate is date!
<div ng-if="(mfstDate| date:'yyyy/MM/dd')>(startDate.slice(6,-2) | date:'yyyy/MM/dd')" style="background-color:#E25D5D">{{startDate.slice(6,-2) | date:'dd/MM/yyyy'}} less {{mfstDate| date:'dd/MM/yyyy'}}</div>
<div ng-if="(mfstDate| date:'yyyy/MM/dd')<(startDate.slice(6,-2) | date:'yyyy/MM/dd')" style="background-color:#E25D5D">{{startDate.slice(6,-2) | date:'dd/MM/yyyy'}} greater {{mfstDate| date:'dd/MM/yyyy'}}</div>
</div>
<div>
mfstDate is formatted string!
<div ng-if="mfstDateString>(startDate.slice(6,-2) | date:'yyyy/MM/dd')" style="background-color:#E25D5D">{{startDate.slice(6,-2) | date:'dd/MM/yyyy'}} less {{mfstDateString}}</div>
<div ng-if="mfstDateString<(startDate.slice(6,-2) | date:'yyyy/MM/dd')" style="background-color:#B8BCEF">{{startDate.slice(6,-2) | date:'dd/MM/yyyy'}} greater {{mfstDateString}}</div>
</div>
</div>