0

App using Angular 4 and bootstrap. I am using an input field that gets the date with month and year (type=month). But when the date saves, I am seeing "yyyy-mm" order. That is fine, but how can I switch the order in the client view to show mm-yyyy or even January 2018?

1
  • use moment.js moment(myDate).format('MMMM-YYYY'); Commented Mar 28, 2018 at 15:35

1 Answer 1

3

You would use the date pipe structure:

{{ dateExpression | date: 'mm-dd-yyyy' }}

There is a good short page about it here that you can read and expand on.

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

3 Comments

The problem with those formats is that It is prefilling in a dd field. So when my month input is "2014-03" , the pipe converts it to 2-28-2014. Is there one that is just for MM/yyyy?
If that's the case you should look into using a 3rd party package like Angular Material which has a datepicker. There's a few others too, lots of which are highly configurable and will probably fit the bill you're looking for: material.angular.io/components/datepicker/overview
you can try like: {{ dateExpression | date: 'MMM-yyyy' }}

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.