Java jansen
Java jansen

Reputation: 197

Angular Material DatePicker ng-model includes time

<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

Answers (2)

camden_kid
camden_kid

Reputation: 12813

It's not possible because ng-model requires a Date. From the docs:

enter image description here

"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:

enter image description here

Upvotes: 1

Jigar7521
Jigar7521

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

Related Questions