0

I'm trying to convert a value to yyyy-MM-dd format. Basically for 06th july 2020 I'm getting date value like this '20200706'. Now i want to convert this value to 2020-07-06.

Currently i'm trying to convert like this, but this is not giving correct result.

fillDateFormatter(dateVal) {
  return this.datepipe.transform(dateVal, 'yyyy-MM-dd');
 };
this.fillDateFormatter('20200706');

So do we have any predefined functions to convert date format like above or how can we convert.. seeking for some guidance. Thanks in advance.

R. Richards
  • 24,603
  • 10
  • 64
  • 64
Roy
  • 880
  • 7
  • 21
  • 39

1 Answers1

0

I would install momentjs npm package. It allows lots of options to manipulate date/time. In your case it would work like this..

console.log(moment('20200706').format('YYYY-MM-DD')); //output: 2020-07-06

Hope it helps.

Thanks.

Obaid
  • 2,563
  • 17
  • 15