[英]How to convert Date in String to Sql date?
I have a date with String format "09-06-2011".我有一个字符串格式为“09-06-2011”的日期。 I need to compare it with another date in java.sql.Date format "2011-06-30 00:00:00".我需要将它与 java.sql.Date 格式“2011-06-30 00:00:00”中的另一个日期进行比较。 How can I convert a String date to a sql date?如何将字符串日期转换为 sql 日期?
Use java.text.DateFormat
and java.text.SimpleDateFormat
and its parse method.使用java.text.DateFormat
和java.text.SimpleDateFormat
及其解析方法。 Be sure to setLenient(false)
.一定要setLenient(false)
。
Use str_to_date
function in MySQL.在 MySQL 中使用str_to_date
function。
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_str-to-date http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_str-to-date
Format:格式:
mysql> SELECT STR_TO_DATE('01,5,2013','%d,%m,%Y');
-> '2013-05-01'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.