6

I have a datepicker on my angularJS WCFrest project

enter image description here

i get the data using

<div class="col-md-4">
  <input id="txtOldDate" type="date" class="datepicker" ng-model="oldDate" />
</div>

but the data that acquired is too complex when i get the data

Fri Dec 16 2016 00:00:00 GMT+07 (SE Asia Standard Time)

i just want to get the value like on the date picker interface

12/16/2016

this is my controller.js

$scope.SearchApproval = function(employeeID, oldDate, newDate, departemen, approver) {
  var promiseGet = GetApproval.GetApprovalData($scope.employeeID, $scope.oldDate, $scope.newDate, $scope.departemen, $scope.approver);
  //GetApprovalData();
  promiseGet.then(function(pl) {
      $scope.GetApprovalData = pl.data
    },
    function(errorPl) {
      console.log('Some Error in Getting Records.', errorPl);
    });
}

is there any way to format the result?

i already try $filter

$scope.oldDate = $filter('date')(new Date(dateString), 'yyyy-MM-dd');

but it give me this error

Error: [ngModel:datefmt] Expected 2016-12-20 to be a date

4
  • 1
    why not save it as it is and filter it to 'yyyy-MM-dd' only when you display it on the page? Commented Dec 20, 2016 at 7:12
  • because i want to send the data to uri and that format make request error because it is too long. something like http://localhost:51458/ServiceRequest.svc/GetApproval?employeeID=22134&oldDate=Fri%20Dec%2009%202016%2000:00:00%20GMT+0700%20(SE%20Asia%20Standard%20Time) Commented Dec 20, 2016 at 7:16
  • the right format should be http://localhost:51458/ServiceRequest.svc/GetApproval?employeeID=&oldDate=2016-12-20) @madalinivascu is there any way to convert the result before i send it to uri? Commented Dec 20, 2016 at 7:17
  • you can do a post request instead of get Commented Dec 20, 2016 at 7:20

3 Answers 3

2

Take a look at this Angular Moment Js and Moment Js it might be helpful.

You can convert this as the below using moment js

$scope.oldDate = moment(dateString).format("YYYY-MM-DD");

To use this you have to add Angular moment in your project and which is explained in above link how to add using nuget or bower or npm.

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

Comments

0

Thanks for all your answer to help me.

Finally i already solve my own problem. The problem is actually on input type = "date". when i change it to type = "text". it can work to send only the date.

this is the result

http://localhost:51458/ServiceRequest.svc/GetApproval?employeeID=&oldDate=2000-01-01

Comments

0

try this

 var mydate = $scope.oldDate.getFullYear()+ "-" +  ($scope.oldDate.getMonth() + 1) + "-" + $scope.oldDate.getDate() 

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.