Reputation: 2281
Using Angular Material Datepicker, when I submit the form I got:
2016-02-15T02:00:00.000Z
And when I tried format at PHP like:
date('Y-m-d', strtotime($post['date']))
I got:
2016-02-14
And when the date goes back to angular:
success: function(data) { $scope.date = new Date(data.date); }
I got:
2016-02-13
So, what am I doing so wrong
[UPDATE]
I put date_default_timezone_set($timezone);
at my index.php
So before that I was doing:
$str = date('d/m/Y', strtotime('+2 day', strtotime($post['date'])));
$workaround = new Date($str);
And now I changed to +1 day
I guess that the php timezone have resolved one of the issues.
Upvotes: 1
Views: 296
Reputation: 22885
I think it is due to you timezone change. Since date from datepicker looks like 2016-02-15T02:00:00.000Z
which means , it is a datetime specific to UTC and when you send it to server, it converts it using your timezone causing previous date.
You can send this date to server after removing decimal part like
2016-02-15T02:00:00
Upvotes: 0