I am using PrimeNg calendar module for picking up a date. I have the following code :
<p-calendar formControlName="valid_till" [dateFormat]="'mm/dd/yy'"></p-calendar>
Now when I select a date for eg: 31st July 2020, in the component, if I log the value I am getting the following :
Fri Jul 31 2020 00:00:00 GMT+0530 (India Standard Time)
But when I pass this value to the server as follows :
this.myService
.save(this.myForm.value, this.editId);
It is passing the date as valid_till: "2020-07-30T18:30:00.000Z" and this value is saved in the database as 2020-07-30 23:59:59. But I have to save it as 2020-07-31 23:59:59. why it is happening like this and how can I save the exact date that I am selected ?
I have tried to add the offset as seen in another post like
newDate = new Date(date_valid_till.getTime() +date_valid_till.getTimezoneOffset() * 60000);
But this has again given me Thu Jul 30 2020 18:29:59 GMT+0530 (India Standard Time), still not the date I would like to have. I only need Thu Jul 31 which I have selected in the date picker.
PS : I am using MySQL database and the column is of type DateTime.
newDate = new Date(date_valid_till.getTime() + date_valid_till.getTimezoneOffset() * 60000);but it has given meThu Jul 30 2020 18:29:59 GMT+0530 (India Standard Time)and it is still one day off