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
'
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.
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.
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.
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().
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With