1

THE SITUATION:

Inside the controller i need to get the current date in order to compare it with other data.

The code is pretty simple:

var today = new Date();

In this way i get the current date in this exact format:

2015-12-24T12:03:58.170Z

I need to format it in order to keep only year-month-day (yyyy-MM-dd)

I know how to format the date in the view but i don't know how to do it inside the controller.

THE QUESTION:

How can i format the current date inside the controller?

Thank you!

1 Answer 1

4

You need to instantiate the date filter in your controller:

function YourController($scope, $filter) {
  var today = new Date();
  var formattedDate = $filter('date')(today, 'yyyy-MM-dd');
}
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.