DB2 時間函式小結 .
--獲取當前日期:
select current date from sysibm.sysdummy1;
values current date;
--獲取當前日期
select current time from sysibm.sysdummy1;
values current time;
--獲取當前時間戳
select current timestamp from sysibm.sysdummy1;
values current timestamp;
--要使當前時間或當前時間戳記調整到 GMT/CUT,則把當前的時間或時間戳記減去當前時區暫存器:
values current time -current timezone;
values current timestamp -current timezone;
--獲取當前年份
values year(current timestamp);
--獲取當前月
values month(current timestamp);
--獲取當前日
values day(current timestamp);
--獲取當前時
values hour(current timestamp);
--獲取分鐘
values minute(current timestamp);
--獲取秒
values second(current timestamp);
--獲取毫秒
values microsecond(current timestamp);
--從時間戳記單獨抽取出日期和時間
values date(current timestamp);
values VARCHAR_FORMAT(current TIMESTAMP,'yyyy-mm-dd');
這條語句比較好,可以定義自由格式,如'yyyymmddhhmmss'
values char(current date);
values time(current timestamp);
--執行日期和時間的計算
values current date+1 year;
values current date+3 years+2 months +15 days;
values current time +5 hours -3 minutes +10 seconds;
--計算兩個日期之間的天數
values days(current date)- days(date('2010-02-20'));
--時間和日期換成字串
values char(current date);
values char(current time);
--要將字串轉換成日期或時間值
values timestamp('2010-03-09-22.43.00.000000');
values timestamp('2010-03-09 22:44:36');
values date('2010-03-09');
values date('03/09/2010');
values time('22:45:27');
values time('22.45.27');
--計算兩個時間戳記之間的時差:
--秒的小數部分為單位
values timestampdiff(1,char(current timestamp - timestamp('2010-01-01-00.00.00')));
--秒為單位
values timestampdiff(2,char(current timestamp - timestamp('2010-01-01-00.00.00')));
--分為單位
values timestampdiff(4,char(current timestamp - timestamp('2010-01-01-00.00.00')));
--小時為單位
values timestampdiff(8,char(current timestamp - timestamp('2010-01-01-00.00.00')));
--天為單位
values timestampdiff(16,char(current timestamp - timestamp('2010-01-01-00.00.00')));
--周為單位
values timestampdiff(32,char(current timestamp - timestamp('2010-01-01-00.00.00')));
--月為單位
values timestampdiff(64,char(current timestamp - timestamp('2010-01-01-00.00.00')));
--季度為單位
values timestampdiff(128,char(current timestamp - timestamp('2010-01-01-00.00.00')));
--年為單位
values timestampdiff(256,char(current timestamp - timestamp('2010-01-01-00.00.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/241379/viewspace-753692/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 函式小結函式
- PHP 時間函式PHP函式
- Golang時間函式及測試函式執行時間案例Golang函式
- T-SQL——函式——時間操作函式SQL函式
- Clickhouse 時間日期函式函式
- 程序間通訊函式介面及應用模板小結函式
- 時間函式:與時間相關那些事。。。函式
- SPL 的日期時間函式函式
- linux下時間有關的函式和結構體Linux函式結構體
- FreeRTOS-04-核心控制函式+時間管理函式函式
- php陣列函式小結PHP陣列函式
- MySQL 的日期和時間函式MySql函式
- python之為函式執行設定超時時間(允許函式執行的最大時間)Python函式
- 探索MySQL高階語句(數學函式、聚合函式、字串函式、日期時間函式)MySql函式字串
- pandas dataframe 時間欄位 diff 函式函式
- 636. 函式的獨佔時間函式
- Go基礎-時間和日期函式Go函式
- MySQL日期和時間函式彙總MySql函式
- Oracle計算時間函式(對時間的加減numtodsinterval、numtoyminterval)Oracle函式
- 關於字串的功能函式小結字串函式
- python中關於時間和日期函式的常用計算總結Python函式
- 如何用DB2的XMLTABLE函式分割XMLCXDB2XML函式
- DB2常用函式與Oracle比較TIDB2函式Oracle
- PostgreSQL:時間——型別、運算子和函式SQL型別函式
- Python之時間和日期使用小結Python
- 函式計算Python連線SQLServer小結函式PythonSQLServer
- Matlab產生隨機數函式小結Matlab隨機函式
- MySQL 日期函式、時間函式在實際場景中的應用MySql函式
- SqlServer 查詢的幾種方式以及數字函式、時間函式的應用總結(迴歸基礎)SQLServer函式
- 校驗十二小時制時間正規表示式
- C時間函式strftime、struct timespec 和 struct timeval函式Struct
- Linux系統時間同步方法小結(NTP)Linux
- jQuery操作iframe中js函式的方法小結jQueryJS函式
- STL區間成員函式及區間演算法總結函式演算法
- elementUI中日期選擇器,控制開始時間小於結束時間UI
- python效能優化之函式執行時間分析Python優化函式
- GO語言————6.11 計算函式執行時間Go函式
- ORACLE中日期和時間函式彙總(轉載)Oracle函式
- hive時間日期函式及典型場景應用Hive函式