3

I had been trying to set the date to a input type="date" using angular's ng-model and value with no success. I tryed to use the documentation of angular JS about the input-date and the only thing I got was to set the year of the input, day and month remained with the placeholder value: "dd/mm/2014".

what I tried:

$scope.value = new Date(2013, 9, 22);

and in my HTML:

<input type="date" id="exampleInput" name="input" ng-model="value" placeholder="yyyy-MM-dd" min="2013-01-01" max="2013-12-31" required />

and what I get is tha input date with: "dd/mm/2013"

I tried using the angular documentation example to be sure that I am doing it right, thats because of the min and max value of the date.

Any idea on how to fill my input date with the date of today ?

Thanks in advance

1
  • true, I Used the solution from that post, works fine. Thanks ! Commented May 23, 2014 at 16:02

4 Answers 4

2
$scope.value = new Date().toISOString().split("T")[0]; // 2014-05-23

tested in chrome.

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

Comments

0

The date format needs to be in a valid ISO-8601 date format (yyyy-MM-dd)

// This won't work
new Date(2013, 9, 22); // Tue Oct 22 2013 00:00:00 GMT+1100 (EST)

try this:

new Date().toISOString().split("T")[0]; // "2014-09-30"

Note: toISOString() will return the UTC timezone.

See: https://docs.angularjs.org/api/ng/input/input%5Bdate%5D

1 Comment

how i can get Indian time zone date
0

The above answers generate "Error: ngModel:datefmt Model is not a date object", at least in angular 1.4.7.

A slight adjustment fixes it:

    $scope.value = new Date(new Date().toISOString().split("T")[0])

Comments

0

I am doing following things,and date get started appearing in mm/dd/yyyy format-

<input type="date" data-ng-model="value"  />

also do this in controller:

$scope.value=new Date();
$scope.value =new Date($scope.value).toISOString().split("T")[0];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.