Angular date and time using DatePipe

Viewed 896

I am using angular DataPipe to display a Date. I have a scenario where we display the date on a table column. The date for that column is set as current date when other column is changed. The requirement is I want to display the date, when I send this column value to server side, I want to include Date and Time. For instance: if the column value gets set at on this time: 05-22-2020 07:25:45 PM. I want to display 05-22-2020, and value that goes is an 05-22-2020 07:25:45 PM.

I am using like this now, this.datePipe.transform(new Date(), 'MM/dd/yyyy');

1 Answers

Your ts file needs to keep the whole date: 05-22-2020 07:25:45 PM and you need to use the date pipe to format the date in the html.

ts:

date: Date = new Date(); // full date

HTML:

<span>{{date| date:'MM/dd/yyyy'}}</span>

Of course you need to modify the date somehow in your ts.

Related