mo obaid
mo obaid

Reputation: 17

I want to convert Date to dd-mm-yyyy

Get(AgrTempId) {
    this.AgreementsService.GetAgreementTemp(AgrTempId).subscribe((res: BaseResponse) => {
      debugger;
      
      this.agrTempValidFrom = new DatePipe('en-US').transform(new Date(res.data["validFrom"]), 'yyyy-MM-dd');
      this.agrTempValidTo = new DatePipe('en-US').transform(new Date(res.data["validTo"]), 'yyyy-MM-dd');
     

    },
      (error) => {
      })
  }

Upvotes: 0

Views: 171

Answers (2)

Prashanth Damam
Prashanth Damam

Reputation: 931

You can use moment for that

moment(new Date()).format('YYYY-MM-DD');

in your case you can use this way

  this.agrTempValidFrom = new DatePipe('en-US').transform(moment(new Date(res.data["validFrom"])).format('YYYY-MM-DD'));
  this.agrTempValidTo = new DatePipe('en-US').transform(moment(new Date(res.data["validTo"])).format('YYYY-MM-DD'));

Upvotes: 3

Shima
Shima

Reputation: 1

Have you seen Format date as dd/MM/yyyy using pipes This answer was useful to me :

var ddMMyyyy = this.datePipe.transform(new Date(),"dd-MM-yyyy");

Upvotes: 0

Related Questions