converting angular date picker date to 'YYYY-MM-DD' format
13,066
const momentDate = new Date(event.value); // Replace event.value with your date value
const formattedDate = moment(momentDate).format("YYYY/MM/DD");
console.log(formattedDate);
![dinith jayabodhi](https://lh4.googleusercontent.com/-6ObSBqClX4E/AAAAAAAAAAI/AAAAAAAAEVM/eBdZ3i312ag/photo.jpg?sz=256)
Author by
dinith jayabodhi
I am undergraduate mastering in Information Technology . I have a passion for for programming and software engineering . I have been working as a freelancer for about 6 months in the software engineering field . my code is for ( i = 'where u are' , i == 'success' , i++) { HardWork(); }
Updated on August 21, 2022Comments
-
dinith jayabodhi almost 2 years
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.