Reputation: 4972
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)
Upvotes: 0
Views: 622
Reputation: 1246
To change the format of the date you do like this
$dateRequired=date('Y-m-d', strtotime($your_date));
In ts file you can add this code to get the date in the correct format
let d=new Date(date value);
let actualDate=d.getDate();
let actualMonth=d.getMonth()+1;
let actualYear=d.getFullYear();
let formattedDate=actualDate + '/' + actualMonth + '/' + actualYear;
Upvotes: 3