bitsCN.com

mysql str_to_date字符串转换为日期

mysql内置函数,在mysql里面利用str_to_date()把字符串转换为日期。

实例:

分隔符一致,年月日要一致

select str_to_date('02/25/1998 12:00:34 AM','%m/%d/%y %h:%i:%s %s') as column_name from table_name;

str_to_date('11/09/2011', '%m/%d/%Y'); -- 2011-11-09

str_to_date('11/09/11' , '%m/%d/%y'); -- 2011-11-09

str_to_date('11.09.2011', '%m.%d.%Y'); -- 2011-11-09

str_to_date('11:09:30', '%h:%i:%s'); -- 11:09:30

str_to_date('11.09.2011 11:09:30', '%m.%d.%Y %h:%i:%s'); -- 2011-11-09 11:09:30

bitsCN.com
09-03 17:45