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.

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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.

2 Comments

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.