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

Asked

Viewed 326 times

0

Hello I have an Android application that takes the date of a Datepicker but I’m not able to convert it to the type accepted by MYSQL in the case Date how could do this?

2 answers

0

You can change the global variables of your database to the format of your application, but I indicate some formatting of the application for the database, to keep the default, but if you want to change the database, the variables are the following and would be like this:

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

0

Dates in Mysql are 'YYYY-MM-DD' format and support a range from '1000-01-01' up to '9999-12-31'. Check if 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()));
  • In this case you are converting the received date to String?

  • I was converting a date object. I updated the example, I think it will be simpler.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.