Home Ask Login Register

Developers Planet

Your answer is one click away!

Pablo February 2016

How to resolve angular datepicker format before and after post?

Using Angular Material Datepicker, when I submit the form I got:


And when I tried format at PHP like:

date('Y-m-d', strtotime($post['date']))

I got:


And when the date goes back to angular:

success: function(data) { $scope.date = new Date(data.date); }

I got:


So, what am I doing so wrong


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.


Zohaib Ijaz February 2016

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


Post Status

Asked in February 2016
Viewed 3,237 times
Voted 8
Answered 1 times


Leave an answer

Quote of the day: live life