My problem is the date picker does not support "DD/MM/YYYY" Format using input, only support by using calendar. and i need that the date picker should allow user enter date '25/11/2016' by using text input
Asked
Active
Viewed 2,932 times
1
-
1Does this answer your question? [How to change Mat-Datepicker date format to DD/MM/YYYY in simplest way?](https://stackoverflow.com/questions/55721254/how-to-change-mat-datepicker-date-format-to-dd-mm-yyyy-in-simplest-way) – Jonathan May 20 '22 at 07:02
-
It does work only if user selects from date picker but I want to parse user manual input also to DD/MM/YYYY. any suggestions will be appreciated. Thanks – Ashok Ketha May 20 '22 at 09:44
3 Answers
1
You can specify a date format in your app material module (if you added one)
const modules = [
MatDatepickerModule,
];
const appDateFormat = {
parse: {
dateInput: 'D-M-YYYY',
},
display: {
dateInput: 'D-M-YYYY',
monthYearLabel: 'MMM YYYY',
dateA11yLabel: 'LL',
monthYearA11yLabel: 'MMMM YYYY',
},
};
@NgModule({
declarations: [],
imports: modules,
exports: modules,
providers: [
{
provide: MAT_DATE_FORMATS,
useValue: appDateFormat,
},
{
provide: DateAdapter,
useClass: MomentDateAdapter,
deps: [MAT_DATE_LOCALE],
},
],
})
export class AppMaterialModule {}
You can also specify a locale in your app.module
providers: [
{ provide: LOCALE_ID, useValue: 'nl-NL' },
],

Jonathan
- 8,771
- 4
- 41
- 78
0
you should configure your app.module.ts like that:
providers: [
{ provide: MAT_DATE_LOCALE, useValue: 'es-ES' },
{
provide: DateAdapter,
useClass: MomentDateAdapter,
deps: [MAT_DATE_LOCALE, MAT_MOMENT_DATE_ADAPTER_OPTIONS],
},
{ provide: MAT_DATE_FORMATS, useValue: MAT_MOMENT_DATE_FORMATS },
],
Instead of 'es-ES', you can choose another.
It will show an alert about using moment, but this configuration is the recommended in Angular Material documentation

Gustavo López Frutos
- 61
- 1
- 6
0
The below will make your date in this format 18-07-2023
{ provide: MAT_DATE_LOCALE, useValue: 'nl-NL' },

Emmanuel Iyen-Mediatrees
- 159
- 8