1

I have an application in which there are several date fields that need to accept values from the user as well as from the database.

I found this solution but still get the error message

Error: [ngModel:datefmt]

http://errors.angularjs.org/1.5.8/ngModel/datefmt?p0=2017-05-03

My code is (you can see a number of attempts I made in comments as well):

var xx = $filter("date")(Date.now(), 'yyyy-MM-dd');
var yy = $filter("date")(Date.now(), 'yyyy-MM-dd');

$rootScope.Global.Time_Window_From = xx; // $filter("date")(Date.now(), 'yyyy-MM-dd'); //'2017-05-02' ; //Date.now() ; //$filter("date")(Date.now(), 'yyyy-MM-dd') ;
$rootScope.Global.Time_Window_To   = yy; // $filter("date")(Date.now(), 'yyyy-MM-dd'); //'2017-05-02' ; //Date.now() ; //$filter("date")(Date.now(), 'yyyy-MM-dd') ;

In addition, what would be the best way to exchange DATE data with an SQL-Server database?

1 Answer 1

2

Documentation from Angularjs:

All date-related inputs like require the model to be a Date object. If the model is something else, this error will be thrown


You should bind to date-type input with only date-type data. By new Date(parameter) will generate a date object of your data.

angular.module("app", [])
  .controller("myCtrl", function($scope, $filter) {
    //$scope.testDate = $filter('date')(Date.now(), 'yyyy/MM/dd');
    $scope.testDate = new Date('2017-05-03');
  });
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<div ng-app="app" ng-controller="myCtrl">
  <input type="date" ng-model="testDate">
</div>

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

3 Comments

BINGO!!!!!! Thanks Pengyy!! What about the second part of my question (i.e. interworking with SQL-Server)? Can you suggest the correct way of doing that?
@FDavidov sorry, I didn't quite use SQLServer for some(long) time... But I do remember there is a set of function can format date to specified format.
No problem. You gained a "V" anyway :-).

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.