0

As you can see I have already changed the opening Date date-picker format bu, I want to change year built format to Year(YYYY) only while keeping other form fields intact. is it possible to do that? or any references.

form-input-date

1

1 Answer 1

1

Angular Material provides MAT_DATE_FORMATS object which is the collection of formats used by Datepicker to parse and display dates. To use custom date format we need to override MAT_DATE_FORMATS with the given formats. Import it and provide your own date format.

 import { MAT_DATE_FORMATS } from '@angular/material';

Define a date format in a custom way as you require.

export const DATE_FORMAT= {
  parse: {
    dateInput: 'LL',
  },
  display: {
    dateInput: 'DD MMM YYYY',
    monthYearLabel: 'YYYY',
    dateA11yLabel: 'LL',
    monthYearA11yLabel: 'YYYY',
  },
};

In @Component, add the provider

 providers: [
    { provide: MAT_DATE_FORMATS, useValue: DATE_FORMAT }
  ]
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.