Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting android date time into mysql datetime

Tags:

android

mysql

Is there any way I can get datetime format like 'YYYY-MM-DD HH:MM:SS' to be stored as datetime format in mysql from android date of format 'MM-DD-YY' and time of format 'HH:MM'

Input : android date 'MM-DD-YY' and android time 'HH:MM'
Output: mysql datetime 'YYYY-MM-DD HH:MM:SS'

like image 865
Rakon_188 Avatar asked Nov 19 '11 13:11

Rakon_188


People also ask

How to convert date time to date in MySQL?

Here is the query to convert from datetime to date in MySQL. mysql> select cast(ArrivalDatetime as Date) as Date from ConvertDateTimeToDate; The following is the output.

How to convert date in MySQL query?

Use STR_TO_DATE() method from MySQL to convert. The syntax is as follows wherein we are using format specifiers. The format specifiers begin with %. SELECT STR_TO_DATE(yourDateColumnName,'%d.

What is the datetime format in MySQL?

MySQL retrieves and displays DATETIME values in ' YYYY-MM-DD hh:mm:ss ' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59' . The TIMESTAMP data type is used for values that contain both date and time parts. TIMESTAMP has a range of '1970-01-01 00:00:01' UTC to '2038-01-19 03:14:07' UTC.

Can we change date format in MySQL?

Change the curdate() (current date) format in MySQL The current date format is 'YYYY-mm-dd'. To change current date format, you can use date_format().


1 Answers

Use SimpleDateFormat to parse and format the dates :

// Parse the input date
SimpleDateFormat fmt = new SimpleDateFormat("MM-dd-yyyy HH:mm");
Date inputDate = fmt.parse("10-22-2011 01:00");

// Create the MySQL datetime string
fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = fmt.format(inputDate);
like image 89
Dalmas Avatar answered Sep 21 '22 18:09

Dalmas