0

I am trying to just get the date from the Datetime. I have below mytime variable which holds the date and time, here I just need the date in the yyyy-MM-dd format

    $scope.mytime = new Date();

I tried doing few things but it doesnt work

$scope.mytime.getdate();

which just returns 8 but I am looking for yyyy-MM-dd

I also did try

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

Got $filter is not defined

1
  • Inject $filter into your controller. Commented Jul 8, 2019 at 17:01

1 Answer 1

1

You should inject the filters while using it in the controller as:

function appController($filter,$scope){

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

}

var app = angular.module('app',[]);
app.controller('appController',appController);

appController.$inject=['$filter','$scope'];
Sign up to request clarification or add additional context in comments.

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.