Mysql中to_char()和str_to_date()函数
转载路径:https://blog.csdn.net/ricardo_mli/article/details/80217512
1.字符串转换成日期格式
str_to_date(date,’%Y-%m-%d’)----->相当于Oracle中的to_char();
例子:
INSERT INTO
t_order(order_time)
VALUES
(str_to_date('2018-05-06','%Y-%m-%d'))
2.日期转换成字符串格式
date_format(date,’%Y-%m-%d’)----->相当于Oracle中的to_date();
例子:
select date_format(order_time, '%Y-%m-%d')from t_order
%Y:代表4位的年份
%y:代表2为的年份
%m:代表月, 格式为(01……12)
%c:代表月, 格式为(1……12)
%d:代表月份中的天数,格式为(00……31)
%e:代表月份中的天数, 格式为(0……31)
%H:代表小时,格式为(00……23)
%k:代表 小时,格式为(0……23)
%h: 代表小时,格式为(01……12)
%I: 代表小时,格式为(01……12)
%l :代表小时,格式为(1……12)
%i: 代表分钟, 格式为(00……59)
%r:代表 时间,格式为12 小时(hh:mm:ss [AP]M)
%T:代表 时间,格式为24 小时(hh:mm:ss)