0
<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.

Java jansen
  • 187
  • 2
  • 15

2 Answers2

1

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

camden_kid
  • 12,591
  • 11
  • 52
  • 88
0

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.

Jigar7521
  • 1,549
  • 14
  • 27
  • i really like to have an automatic binding to the variable "newResearch.plannedStartDate" with the use of ng-model in date picker. using that in controller requires something to be triggered before converted. – Java jansen Oct 17 '16 at 09:04
  • You need to do this at that time when date going to be save in database, and when it is going to be show in md-datepicker, don't forget to keep data-type of this field as date in mysql. – Jigar7521 Oct 17 '16 at 09:13