mysql:
//字符串转日期
select str_to_date('09/01/2009','%m/%d/%Y') from dual;
select str_to_date('20140422154706','%Y%m%d%H%i%s') from dual;
select str_to_date('2014-04-22 15:47:06','%Y-%m-%d %H:%i:%s') from dual;
//日期转字符串
select date_format('2014-04-22 15:47:06','%Y-%m-%d %H:%i:%s') from dual;
oracle:
//日期转字符串
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') as nowTime from dual;
select to_char(sysdate,'yyyy') as nowYear from dual; //获取时间的年
select to_char(sysdate,'mm') as nowMonth from dual; //获取时间的月
select to_char(sysdate,'dd') as nowDay from dual; //获取时间的日
select to_char(sysdate,'hh24') as nowHour from dual; //获取时间的时
select to_char(sysdate,'mi') as nowMinute from dual; //获取时间的分
select to_char(sysdate,'ss') as nowSecond from dual; //获取时间的秒
//字符串转日期
select to_date('2004-05-07 13:23:44','yyyy-mm-dd hh24:mi:ss') from dual;
本文介绍了在MySQL和Oracle数据库中如何将字符串转换为日期格式以及如何将日期格式转换为字符串的方法。针对不同日期格式的需求,提供了多种实用的SQL语句示例。
2332

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



