I have this angular material date picker:
<mat-form-field color="warn">
<input matInput [matDatepicker]="picker" formControlName="add_date" placeholder="Date">
<mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
<mat-datepicker #picker></mat-datepicker>
</mat-form-field>
This value is not readable with MysQL as is not the required format Y-m-d
, so I convert the date sent to PHP like the following:
$dateAdded = strtotime('y-m-d', $dateAdded);
$dateAdded = date('Y-m-d', $dateAdded);
And everything added to database now is having the date of: Jan 1, 1970
.
The format sent from Angular is like:
date: Fri Sep 14 2018 00:00:00 GMT+0300 (Eastern European Summer Time)
To change the format of the date you do like this
In ts file you can add this code to get the date in the correct format