how to save date with Date type in MYSQL and return to an Android app

0

Hello, I have an Android application that takes the date from a DatePicker but I am not able to convert it to the type accepted by MYSQL in the Date case how could I do this?

    
asked by anonymous 13.11.2017 / 10:56

2 answers

0

The dates in MySQL have the format 'YYYY-MM-DD' and support a range of '1000-01-01' through '9999-12-31'. Make sure the date you are reporting is in this format and is valid. If you need to convert, use the SimpleDateFormat . Ex:

SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd");

String dateFormat = dateformat.format(new Date(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth()));
    
13.11.2017 / 13:33
0

You can change the global variables of your database to the format of your application, but I indicate some formatting of the application to the database, to maintain the default, but if you want to change the database, the variables are the would look like this:

SET @@ date_format = '% d /% m /% Y'; SET @@ datetime_format = '% d /% m /% Y% H:% i:% s';

    
13.11.2017 / 21:38