2
votes

I am using the angular material date picker . When I get the date I get the value as

Wed Sep 12 2018 00:00:00 GMT+0530 (India Standard Time)

but I need it to be in 'YYYY-MM-DD'

Here is my code so far

 <mat-form-field>
            <input matInput [matDatepicker]="picker" placeholder="Select a date" [(ngModel)] = 'dateSel' data-date-format='YYYY-MM-DD' >
            <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
            <mat-datepicker #picker></mat-datepicker>
        </mat-form-field>

I tried to use the moment.js application too. But I ended up with complicated date object.

1
Post your code what you have done so far ?Sudhir Ojha

1 Answers

5
votes
 const momentDate = new Date(event.value); // Replace event.value with your date value
 const formattedDate = moment(momentDate).format("YYYY/MM/DD");
 console.log(formattedDate);