I have a date with String format "09-06-2011". I need to compare it with another date in java.sql.Date format "2011-06-30 00:00:00". How can I convert a String date to a sql date ?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Use str_to_date
function in MySQL.
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'
回答2:
Use java.text.DateFormat
and java.text.SimpleDateFormat
and its parse method. Be sure to setLenient(false)
.