Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

converting angular date picker date to 'YYYY-MM-DD' format

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.

like image 360
dinith jayabodhi Avatar asked Aug 31 '25 02:08

dinith jayabodhi


1 Answers

 const momentDate = new Date(event.value); // Replace event.value with your date value
 const formattedDate = moment(momentDate).format("YYYY/MM/DD");
 console.log(formattedDate);
like image 104
Ashraful Islam Avatar answered Sep 03 '25 03:09

Ashraful Islam