Ionic default date picker shows one day behind after inserting data to the databse

Hi guys!!! I’m creating an ionic application and I have faced two problems regarding ionic default datepicker.

1. I have used ionic default date picker (input type=“date”) to get date details. Eg: From date and To date

When I select a specific date in the datepicker it shows as it is but, after inserting that data using ng-model in the database it shows one day behind the date which I selected from the database.

I think this is due to a timezone issue. But I have no idea how to fix this issue. This is how it works


After inserting to the databse


2. Second problem is I want to disable the dates before today in the date picker because it is showing all the past days as well. I want to enable dates from today onwards.

Waiting for a quick response from you all. Thank you :slight_smile:

your first problem is due to utc timing conversion your client side and server are may be in two time region just cross check it you can solve this issue by saving you can save the utc time and whilr retrieving you can convert the utc time to local datetime !
for your second question i am handled the same situation with $cordovaDatePicker

Yes my client and server are in two countries. But don’t you have a solution for this first problem?

And do you have any sample code of $cordovaDatePicker and how to use it?

Thank you :slight_smile:

try any of this

1 Like

Thank you very much! I’ll try these and let you know :slight_smile:

As it was already said your 1) problem is due to time problems. Check what is sent to the backend from your app to confirm that the data is identical to what is displayed in the picker. Then you know it is a backend + database problem, not one of your app itself.

1 Like

Yes. How to fix this timezone issue?

This is not really an Ionic question any more, but you make sure the data is saved in the right format in the database. phpMyAdmin and MySQL often try to be smart about datetime fields, so make sure to set the timezone information everywhere (or better: use UTC to save data).