-1

I am using Angular version 12 and datePipe.transform, I am getting date in dd/MM/yyyy format in string and I want to bind that date in my reactive form ( to edit the form ) where I use Angular material date picker Basic Angular Date picker

Demo

I am sure I am doing something wrong but I don't know what? Can anyone help me?

SOLUTION For me:

MomentJS is the best solution for all date and time glitches!

If you are looking for alternative of moment then below is the link you must look into it. - Thanks to Jakub Kozak

https://medium.com/swlh/best-moment-js-alternatives-5dfa6861a1eb

Raj
  • 15
  • 8
  • https://stackblitz.com/edit/angular-ivy-srh92c?file=src%2Fapp%2Fapp.component.ts – Raj Nov 13 '21 at 17:40

1 Answers1

1

Just change this:

    const CreatedDate1 = this.datePipe.transform(CreatedDate, 'long');

P.S: You were using the string '09/11/2021' instead your formatted variable 'CreatedDate'.

By the way, as a piece of advice, it's a good practice to use "CamelCase" for naming your variables and consts in Angular ('createdDate', in your example), and leave the "PascalCase" (as 'CreatedDate') for the Interface/Classes/... I left an article about it HERE See you!

  • Strange! if I use 'long' I could see November but unfortunately I cant bind long format in date picker - it needs certain date format which I have mentioned in DEMO 'yyyy-dd-MM'.. If I use that format it will show September in date picker! when "long" format shows correct result in console! @Juan Vicente Berzosa Tejero any idea? – Raj Nov 13 '21 at 19:05
  • Any other way to bind date in Angular material date picker? – Raj Nov 13 '21 at 20:06
  • your answer is right. but it could not help me in bind the value! anyways, Thanks for the link and your time! – Raj Nov 13 '21 at 22:00