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) => {
})
}
Asked
Active
Viewed 141 times
0

R. Richards
- 24,603
- 10
- 64
- 64

mo obaid
- 17
- 3
2 Answers
3
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'));

Prashanth Damam
- 841
- 8
- 25
-
you imported moment? – Prashanth Damam Jul 05 '21 at 13:01
-
There is no error but it appears like this mm-dd-yyyyy – mo obaid Jul 05 '21 at 13:06
-
`MM-DD-YYYY` You can try this. You can refer to the moment.js docs if you need more info – Prashanth Damam Jul 05 '21 at 13:24
-
the format in Api is yyyy-MM-dd . i can't change it – mo obaid Jul 05 '21 at 13:26
-
You can format any date format string to upper case. `"yyyy-MM-dd".toUpperCase()` – Prashanth Damam Jul 05 '21 at 13:35
-
What will be the benefit? – mo obaid Jul 05 '21 at 13:54
-
It will be same everytime irrespective of the case followed in the api. It supports all the formats which we use in the moment.js – Prashanth Damam Jul 05 '21 at 14:07
0
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");

Shima
- 1
- 3
-
you can use a language identifier to highlight the code and make it better to read – I_love_vegetables Jul 12 '21 at 09:38