question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow multiple DateFormats in datepicker

See original GitHub issue

Bug, feature request, or proposal:

feature

What is the expected behavior?

I want to use 2 different Date Formats in one Component.

idea

{
  provide: MAT_DATE_FORMATS, useValue: {
    "date": DATE_FORMATS,
    "other": OTHER_DATE_FORMATS,
    ...
  }
}
...
<mat-datepicker dateFormat="date"></mat-datepicker>
...
<mat-datepicker dateFormat="other"></mat-datepicker>
...

What is the current behavior?

I can replace Date Formats for component.

What are the steps to reproduce?

What is the use-case or motivation for changing an existing behavior?

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Is there anything else we should know?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:10
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

14reactions
mmalerbacommented, Jul 26, 2019

If you’re looking for a way to have a couple static formats, it is possible: https://stackblitz.com/edit/angular-azrzg5?file=app/datepicker-moment-example.ts

Unfortunately, if you want to have it be dynamic based on a directive input (e.g. <mat-form-field dateFormat="LL">) This won’t work because there isn’t currently a mechanism to tell the datepicker that the format has updated.

It would be nice to make the more dynamic version work as well, but its not super high on our priority list

3reactions
mmalerbacommented, Jun 2, 2020

What was the error you were seeing? I don’t think it should be necessary to import @angular/compiler. I updated my stackblitz to the latest version of Angular and it still seems to be working without that import: https://stackblitz.com/edit/angular-azrzg5-pky8e5?file=main.ts

Read more comments on GitHub >

github_iconTop Results From Across the Web

jQuery Datepicker that supports multiple formats
This 'Unobtrusive Date-Picker Widget V5' seems to accept multiple formats. I did a quick test of all three of the formats you supplied, ......
Read more >
How can add multiple date formats in datepicker?
Greetings friends , I have the following code: $(function() { $( "#inicio" ).datepicker({ dateFormat: "yy-mm-dd" }); $( "#termino" ) ...
Read more >
How to allow multiple input formats? · Issue #605 - GitHub
The dateFormat prop can accept an array of formats where they will all be used for reading but the first one is used...
Read more >
Angular Material datepicker with many custom date formats |
Hi! In this article, I'd like to show you how to create datepickers with many custom date formats in Angular Material. Introduction. Hi!...
Read more >
How to Allow Date Range or Multiple Dates in Date Picker
Would you like to customize the date picker to allow for a date range or even multiple dates? You can easily accomplish this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found