mysql中str_to_date函数的介绍与用法

成熟不是心变老,而是眼泪在眼里打转却还持续微笑。积极的人在每一次忧患中都是看到一个机会,而消极的人则是在每个机会都是会看到某种忧患。

在mysql中有个 date_format 函数的反函数 str_to_date ,它可以将一个字符串转换成指定格式的时间日期的格式,其使用方法与 date_format 函数差不多。

mysql str_to_date 函数的介绍

str_to_date:将一个字符串形式的日期转换成指定格式的时间日期表达方式。

语法:

str_to_date(str,format)

参数:

str:一个字符串形式的时间日期格式

format:指定要转换日期的格式。

注:

format 预定义说明字符串 参考:https://www.feiniaomy.com/post/743.html

mysql str_to_date() 函数用法

示例1:str_to_date 转换一个日期的字符串

select str_to_date('08/09/2008', '%m/%d/%Y');
select str_to_date('08/09/2008', '%d/%m/%Y');
select str_to_date('08.09.2008', '%d.%m.%Y');

mysql中str_to_date函数的介绍与用法

示例2:str_to_date 转换一个时间的字符串

select str_to_date('08:09:30', '%h:%i:%s');
select str_to_date('08:09:30', '%i:%h:%s');
select str_to_date('080930', '%i%h%s');

mysql中str_to_date函数的介绍与用法

到此这篇关于mysql中str_to_date函数的介绍与用法就介绍到这了。人不报应,天报应,因果是存在的。千万不要干坏事。更多相关mysql中str_to_date函数的介绍与用法内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!

标签: mysql 数据库