Reputation: 197
<md-input-container>
<label>Enter date</label>
<md-datepicker ng-model="newResearch.plannedStartDate"></md-datepicker>
</md-input-container>
the value of the planned start date is " 1985-03-05T16:00:00.000Z " i need the value to be exactly 1985-03-05 only.
Upvotes: 0
Views: 367
Reputation: 12813
It's not possible because ng-model
requires a Date. From the docs:
"1985-03-05T16:00:00.000Z" is actually the way console.log()
displays the Date object (possibly using JSON.stringify()).
If you check this CodePen, you will see that the following lines of code:
console.log(typeof $scope.newResearch.plannedStartDate);
// This is a check for a Date object from Christoph's answer - http://stackoverflow.com/a/643827/782358
console.log(typeof $scope.newResearch.plannedStartDate.getMonth === 'function');
console.log(JSON.stringify($scope.newResearch.plannedStartDate));
produce the following output:
Upvotes: 1
Reputation: 1579
In your controller please apply this:
var newDate = $filter('date')(value, "yyyy-MM-dd");
$scope.newResearch.plannedStartDate = newDate;
By use of filter you can achieve what your needs.
Upvotes: 0