時間和日期處理函式
--檢索年份是2007的所有 prod_end資料
select * from products
where to_number(to_char(prod_end,'yyyy'))= 2007;
select * from products
where prod_end between
to_date('20060708','yyyy-mm-dd') and to_date('20080708','yyyy-mm-dd');
--求某天是星期幾
select to_char(to_date('2002-08-26','yyyy-mm-dd'),'day') from dual; dual為偽表 ;
--兩個日期間的天數
select floor(sysdate - to_date('20080516','yyyymmdd')) from dual;
select ceil(to_date('20080518101812','yyyymmdd hh:mi:ss') - to_date('20080516101815','yyyymmdd hh:mi:ss')) from dual;--2 天花板函式,即加入正小數至最近整數
select floor(to_date('20080518101812','yyyymmdd hh:mi:ss') - to_date('20080516101815','yyyymmdd hh:mi:ss')) from dual;--1 地板函式,即捨去正小數至最近整數
--查詢2008-05-03至2008-05-12間除星期一和七的天數
select count(*)
from ( select rownum-1 rnum
from all_objects
where rownum <= to_date('2008-05-12','yyyy-mm-dd') - to_date('2008-05-03','yyyy-mm-dd')+1)
where to_char( to_date('2008-05-03','yyyy-mm-dd')+rnum-1, 'd' )
not in ( '1', '7' )
--獲取05-03-2008至06-02-2008間有多少個月,如果乙個月以下的,返回小數,如這個例子返回:0.967741935483871
select months_between(to_date('06-02-2008','mm-dd-yyyy'),
to_date('05-03-2008','mm-dd-yyyy')) "months" from dual;
--獲取小時,分鐘,秒,年月日
select sysdate ,to_char(sysdate,'hh') from dual;
select to_char('sdsf','sd') from dual;
--找出今年的天數
select add_months(trunc(sysdate,'year'), 12) - trunc(sysdate,'year') from dual
--閏年的處理方法
select to_char( last_day( to_date('02' || '2008','mmyyyy') ), 'dd' ) from dual
--一年的第幾天
select to_char(sysdate,'ddd'),sysdate from dual
--是從當前開始下乙個星期五的具體時間
select next_day(sysdate,6) from dual
--floor((date2-date1) /365) 作為年
--floor((date2-date1, 365) /30) 作為月
--mod(mod(date2-date1, 365), 30)作為日.
--to_char,函式功能,就是將數值型或者日期型轉化為字元型,fm :除空格
--9999999.0099:允許小數點左邊最大正數為7位,小數點右邊最少2位,最多4位,且在第5位進行四捨五入
select to_char(123.02,'fm9999999.00009') from dual
select to_char(0.123,'fm0.999') from dual
日期函式(學習筆記)
日期函式 獲取當前系統時間 select sysdate from dual 獲取的是當前系統的時間 查詢距離今天3天後,和3天前的日期 select sysdate 今天,sysdate 3 三天前,sysdate 3 三天後 from dual 查詢出每個員工入職到今天的入職天數,以及十天前每個...
日期函式(學習筆記)
日期函式 獲取當前系統時間 select sysdate from dual 獲取的是當前系統的時間 查詢距離今天3天後,和3天前的日期 select sysdate 今天,sysdate 3 三天前,sysdate 3 三天後 from dual 查詢出每個員工入職到今天的入職天數,以及十天前每個...
Hive日期時間函式學習
1 日期字串與unixtime互轉 日期函式unix時間戳轉日期函式 from unixtime 語法 from unixtime bigint unixtime string format 返回值 string 說明 轉化unix時間戳 從1970 01 01 00 00 00 utc到指定時間的...