Oracle日期函式 timestamp

2021-08-17 03:10:31 字數 1346 閱讀 8724

timestamp資料型別:是date的擴充套件,可以儲存年、月、日、小時、分鐘、秒,同時還可以儲存秒的小數部分。

timestamp以日期格式輸出表示

select to_char(to_timestamp('2009-7-30','yyyy-mm-dd hh24:mi:ss') ,'yyyy-mm-dd hh24:mi:ss')fromdual;

結果為:2009-07-30 00:00:00

date格式的時間差,以秒為單位:

select (to_date('2009-7-30','yyyy-mm-dd hh24:mi:ss') -to_date('2009-7-29','yyyy-mm-dd hh24:mi:ss')) *86400as"itvtime"fromdual;

結果為:86400

timestamp格式求時間差,以秒為單位:

select (to_date(to_char(to_timestamp('2009-7-30','yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss') -to_date(to_char(to_timestamp('2009-7-29','yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss')) *86400as"mtime"fromdual;

結果為:86400

求任意timestamp格式的時間戳,據2023年01月01日的毫秒數

select (to_date(to_char(to_timestamp('2009-7-30','yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss') -to_date('1970-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss')) *86400000fromdual;

結果為:1248912000000

根據日期求當月天數:

select add_months(trunc(to_date('2009-9','yyyy-mm'),'mm'),1) - trunc(to_date('2009-9','yyyy-mm'),'mm')fromdual;

結果為:30

本文**自天善社群georgeyao部落格,

ORACLE 日期函式

1.select to char to date 2011 5 1 yyyy mm dd day from dual 返回星期日 select to char to date 2011 5 1 yyyy mm dd day nls date language american from dual 返...

oracle日期函式

說明 用於從乙個日期值增加或減少一些月份 d代表乙個日期 n為正數則代表在d日期 上增加n 月份,n 為負數則代表在 d日期上減少n月 例 select add months sysdate,12 next year from dual 2 current date 說明 返回當前會話時區中的當前日...

oracle日期函式

oracle取上週一到週末日期的查詢語句 oracle 取上週一到週末的sql 這樣取的是 在一周內第幾天,是以週日為開始的 selectto char to date 20130906 yyyymmdd d fromdual 結果 6 注釋 2013.09.06是周五,為本週的第六天 select...