MySQL Str to Date (字符串转换为日期)
函数:str_to_date(str, format)
select
str_to_date(
'08/09/2008'
,
'%m/%d/%Y'
);
-- 2008-08-09
select
str_to_date(
'08/09/08'
,
'%m/%d/%y'
);
-- 2008-08-09
select
str_to_date(
'08.09.2008'
,
'%m.%d.%Y'
);
-- 2008-08-09
select
str_to_date(
'08:09:30'
,
'%h:%i:%s'
);
-- 08:09:30
select
str_to_date(
'08.09.2008 08:09:30'
,
'%m.%d.%Y %h:%i:%s'
);
-- 2008-08-09 08:09:3
select date_format(now(),'%Y-%m-%d %T')
----当前时间---2017-06-01 09:33:42
本文介绍了MySQL中使用str_to_date函数将字符串转换为日期格式的方法。包括多种日期和时间字符串的格式化示例。

1862

被折叠的 条评论
为什么被折叠?



