How to convert Date in String to Sql date?

£可爱£侵袭症+ 提交于 2019-12-13 03:57:25

问题


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).



来源:https://stackoverflow.com/questions/6305809/how-to-convert-date-in-string-to-sql-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!