加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Oracle/mysql中日期函数

发布时间:2020-12-12 16:33:16 所属栏目:百科 来源:网络整理
导读:最近在项目中使用oracle数据库,发现oracle跟mysql中函数还是有一些差别的,整理一下关于日期函数的使用。 日期/时间转换为字符串函数 Oracle 日期/时间转字符串函数:to_char(createDate,'yyyy-mm-dd hh24:mi:ss') 字符串转日期/时间函数:TO_Date("2017-04

最近在项目中使用oracle数据库,发现oracle跟mysql中函数还是有一些差别的,整理一下关于日期函数的使用。


日期/时间转换为字符串函数

Oracle

日期/时间转字符串函数:to_char(createDate,'yyyy-mm-dd hh24:mi:ss')

字符串转日期/时间函数:TO_Date("2017-04-11 06:30:01",'yyyy-mm-dd hh24:mi:ss')

MySql

日期/时间转字符串函数:DATE_FORMAT(createDate,'%Y-%m-%d %H:%i:%s')

字符串转日期/时间函数:str_to_date("2017-04-11 06:30:01",'%Y-%m-%d %H:%i:%s')


日期/时间增减函数

Oracle

增减一小时:
createDate+1/24
createDate-1/24
增减一天:
createDate+1
createDate-1
增减一月:
add_months(createDate,1)
add_months(createDate,-1)
增减一季度:
add_months(createDate,3)
add_months(createDate,-3)
增减一年:
add_months(createDate,12)
add_months(createDate,-12)
Mysql


增减一小时:
date_sub(createDate,interval -1 hour)
date_sub(createDate,interval 1 hour)
增减一天:
date_sub(createDate,interval -1 day)
date_sub(createDate,interval 1 day)
增减一月:
date_sub(createDate,interval -1 month)
date_sub(createDate,interval 1 month)
增减一季度:
date_sub(createDate,interval -3 month)
date_sub(createDate,interval 3 month)
增减一年:
date_sub(createDate,interval -1 year)
date_sub(createDate,interval 1 year)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读