0

Hi am trying to convert convert 2020-02-17 to (ddd, MMM Do YYYY) using moment.js

 transform(value: any, args?: any): any {
    console.log(value)
    console.log(moment(value).format("ddd, MMM Do YYYY"))
    return moment(value).format("ddd, MMM Do YYYY");
  }

i have created a pipe for it but it is returning me the value based on current date can somebody help

juhi
  • 558
  • 1
  • 10
  • 19
  • Could you please create a StackBlitz sample for the same? Also the cases you tested. – Jins Thomas Shaji Feb 14 '20 at 09:54
  • 1
    why not use date pipe angular? https://stackoverflow.com/questions/35144821/angular-use-pipes-in-services-and-components: `new DatePipe().transform(new Date(value), 'ddd, MMM yyyy');` – Eliseo Feb 14 '20 at 09:57

2 Answers2

0

This should be working, as you can see on this example : JSFiddle

transform(value: any, args ?: any): any {
  return moment(value).format("ddd, MMM Do YYYY");
}

So your transform pipe should return Mon, Feb 17th 2020.

See Angular Example.

Zooly
  • 4,736
  • 4
  • 34
  • 54
0

This happens if your value is sent blank or null check your value again.