0

I'm working now with Angular material datepicker and I use the moment dateadapter as dateadapter.

It works really great but the displayed date on the input doesn't suit my needs. It shows a date in DD/MM/YYYY format while I need it in DD/MM/YY. (eg. 25/7/2019 should be 25/07/19)

Since I can't find documentation on this display format, I'm gonna need a little help to figure out how to do this.

Buu97
  • 158
  • 2
  • 15

2 Answers2

1

You can set your custom date formats. In your ts file do like this:

export const MY_FORMATS = {
  display: {
    dateInput: 'DD/MM/YY'
  },
};

@Component({
  selector: 'demo-component',
  templateUrl: './demo.component.html',
  styleUrls: ['./demo.component.scss'],
  providers: [
    {provide: MAT_DATE_FORMATS, useValue: MY_FORMATS},
  ],
})
Tushar
  • 1,948
  • 1
  • 13
  • 32
  • Thanks. It worked. Can you explain why does the constant MY_FORMATS need to be exported for it to work? I tried it before posting my question here but I omitted the export and of course, it didn't work. – Buu97 Jul 25 '19 at 07:44
0
Use Custom Date Format from material date format

export const CustomFormat = { display: { dateInput: 'DD/MM/YY' } }; @Component({ selector: 'datecomponent', templateUrl: './datecomponent.html', providers: [ {provide: MAT_DATE_FORMATS, useValue: CustomFormat}, ] })