oracle獲取當前時間

2021-10-01 17:35:32 字數 2103 閱讀 8467

select to_char(sysdate,『yyyy-mm-dd hh24:mi:ss』) from dual;

select to_char(sysdate,『yyyy-mm-dd hh24:mm:ss』) from dual; 容易出錯

elect to_char(sysdate,『yyyy-mm-dd hh24:mi:ss』) from dual;

oracle裡獲取乙個時間的年、季、月、周、日的函式

select to_char(sysdate, 『yyyy』 ) from dual; --年

select to_char(sysdate, 『mm』 ) from dual; --月

select to_char(sysdate, 『dd』 ) from dual; --日

select to_char(sysdate, 『q』) from dual; --季

select to_char(sysdate, 『iw』) from dual; --周–按日曆上的那種,每年有52或者53周

獲取系統日期: sysdate()

格式化日期:

to_char(sysdate(),'yy/mm/dd hh24:mi:ss)

或 to_date(sysdate(),'yy/mm/dd hh24:mi:ss)

select to_char(sysdate,『yyyy-mm-dd hh24:mi:ss』) from dual;

select to_char(sysdate,『yyyy-mm-dd hh24:mm:ss』) from dual;

select to_char(sysdate,『yy-mm-dd hh24:mi:ss』) from dual

select to_date(『2009-12-25 14:23:31』,『yyyy-mm-dd,hh24:mi:ss』) from dual

而如果把上式寫作:

select to_date(『2009-12-25 14:23:31』,『yyyy-mm-dd,hh:mi:ss』) from dual

則會報錯,因為小時hh是12進製,14為非法輸入,不能匹配。

轉換的格式:

表示 year 的:

y 表示年的最後一位 、

yy 表示年的最後2位 、

yyy 表示年的最後3位 、

yyyy 用4位數表示年

表示month的:

mm 用2位數字表示月 、

mon 用簡寫形式, 比如11月或者nov 、

month 用全稱, 比如11月或者november

表示day的:

dd 表示當月第幾天 、

ddd 表示當年第幾天 、

dy 當周第幾天,簡寫, 比如星期五或者fri 、

day 當周第幾天,全稱, 比如星期五或者friday

表示hour的:

hh 2位數表示小時 12進製 、

hh24 2位數表示小時 24小時

表示minute的:

mi 2位數表示分鐘

表示second的:

ss 2位數表示秒 60進製

表示季度的:

q 一位數 表示季度 (1-4)

另外還有ww 用來表示當年第幾周 w用來表示當月第幾周。

當前時間減去7分鐘的時間

select sysdate,sysdate - interval 『7』 minute from dual;

當前時間減去7小時的時間

select sysdate - interval 『7』 hour from dual;

當前時間減去7天的時間

select sysdate - interval 『7』 day from dual;

當前時間減去7月的時間

select sysdate,sysdate - interval 『7』 month from dual;

當前時間減去7年的時間

select sysdate,sysdate - interval 『7』 year from dual;

時間間隔乘以乙個數字

select sysdate,sysdate - 8*interval 『7』 hour from dual;

oracle獲取當前時間

用法to char sysdate,yyyy mm dd hh24 mi ss 把時間變成字串 用法to date 2015 08 12 15 53 37 yyyy mm dd hh24 mi ss 把字串變成時間 用法to number把字串變成數字 用法trunc負責擷取數字或者字串 selec...

獲取當前時間

獲取日期 時間 datetime.now.tostring 2008 9 4 20 02 10 datetime.now.tolocaltime tostring 2008 9 4 20 12 12 獲取日期 datetime.now.tolongdatestring tostring 2008年9...

獲取當前時間

直接上可以執行的 檔案 獲取當前時間.cpp 方案 time 優點 僅使用c標準庫 缺點 只能精確到秒級 include time.h include stdio.h int main void 方案二getlocaltime 優點 能精確到毫秒級 缺點 使用了windows api include...