Oracle獲取一週前,一個月前,一年前的日期
阿新 • • 發佈:2019-02-05
TO_DATE格式(以時間:2007-11-02 13:45:25為例)
Year:
yy two digits 兩位年 顯示值:07
yyy three digits 三位年 顯示值:007
yyyy four digits 四位年 顯示值:2007
Month:
mm number 兩位月 顯示值:11
mon abbreviated 字符集表示 顯示值:11月,若是英文版,顯示nov
month spelled out 字符集表示 顯示值:11月,若是英文版,顯示november
Day:
dd number 當月第幾天 顯示值:02
ddd number 當年第幾天 顯示值:02
dy abbreviated 當週第幾天簡寫 顯示值:星期五,若是英文版,顯示fri
day spelled out 當週第幾天全寫 顯示值:星期五,若是英文版,顯示friday
ddspth spelled out, ordinal twelfth
Hour:
hh two digits 12小時進位制 顯示值:01
hh24 two digits 24小時進位制 顯示值:13
Minute:
mi two digits 60進位制 顯示值:45
Second:
ss two digits 60進位制 顯示值:25
其它
Q digit 季度 顯示值:4
WW digit 當年第幾周 顯示值:44
W digit 當月第幾周 顯示值:1
24小時格式下時間範圍為: 0:00:00 - 23:59:59....
12小時格式下時間範圍為: 1:00:00 - 12:59:59 ....
1. 日期和字元轉換函式用法(to_date,to_char)
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; //獲取時間的秒
Year:
yy two digits 兩位年 顯示值:07
yyy three digits 三位年 顯示值:007
yyyy four digits 四位年 顯示值:2007
Month:
mm number 兩位月 顯示值:11
mon abbreviated 字符集表示 顯示值:11月,若是英文版,顯示nov
month spelled out 字符集表示 顯示值:11月,若是英文版,顯示november
Day:
dd number 當月第幾天 顯示值:02
ddd number 當年第幾天 顯示值:02
dy abbreviated 當週第幾天簡寫 顯示值:星期五,若是英文版,顯示fri
day spelled out 當週第幾天全寫 顯示值:星期五,若是英文版,顯示friday
ddspth spelled out, ordinal twelfth
Hour:
hh two digits 12小時進位制 顯示值:01
hh24 two digits 24小時進位制 顯示值:13
Minute:
mi two digits 60進位制 顯示值:45
Second:
ss two digits 60進位制 顯示值:25
其它
Q digit 季度 顯示值:4
WW digit 當年第幾周 顯示值:44
W digit 當月第幾周 顯示值:1
24小時格式下時間範圍為: 0:00:00 - 23:59:59....
12小時格式下時間範圍為: 1:00:00 - 12:59:59 ....
1. 日期和字元轉換函式用法(to_date,to_char)
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; //獲取時間的秒