mysql 格式化时间(str_to_date,DATE_FORMAT)!

实例1:

 

select if (str_to_date(column1, '%m/%d/%Y %r') is null,
if (str_to_date(column1, '%Y-%m-%d') is null,
str_to_date(column1,
'%c/%e/%Y %T'), str_to_date(column1, '%Y-%m-%d')),
str_to_date(column1,
'%m/%d/%Y %r')) as a from t

 

实例2:

 

select
DATE_FORMAT(STR_TO_DATE(REPLACE (REPLACE (Date, 'AM', ''), 'PM', ''),
       '%c/%e/%Y %k:%i:%s %p'), '%Y-%m-%d') as Date as b from t

你可能感兴趣的:(Sql)