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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SQL時間函式總結(二)SQL函式
- 常用函式--時間函式函式
- 時間函式函式
- 函式小結函式
- PHP 時間函式PHP函式
- 日期時間函式函式
- oracle時間函式Oracle函式
- MySQL時間函式MySql函式
- Sql時間函式SQL函式
- Golang時間函式及測試函式執行時間案例Golang函式
- 函式ZwQuerySystemInformation小結函式ORM
- Oracle 函式小結Oracle函式
- RANK函式小結函式
- T-SQL——函式——時間操作函式SQL函式
- oracle 時間函式sysdateOracle函式
- Oracle 時間函式NumToYMInterval()Oracle函式
- 時間函式對比函式
- Teradata 時間函式函式
- 時間處理函式函式
- mysql時區與時間函式MySql函式
- mysql 字元函式小結MySql字元函式
- linux系統程式設計之檔案與IO(七):時間函式小結Linux程式設計函式
- js時間小總結JS
- oracle時間間隔轉換函式Oracle函式
- MySql 時間比較:DATEDIFF函式與大於小於號MySql函式
- SPL 的日期時間函式函式
- mysql中的時間函式MySql函式
- MySQL日期時間函式大全MySql函式
- mysql幾個時間函式MySql函式
- MySQL 日期時間函式大全MySql函式
- ORACLE日期時間函式大全Oracle函式
- SQLServer時間日期函式速查SQLServer函式
- C語言時間函式C語言函式
- php陣列函式小結PHP陣列函式
- DB2函式大全DB2函式
- FreeRTOS-04-核心控制函式+時間管理函式函式
- Sql Server函式全解(4):日期和時間函式SQLServer函式
- Sql Server函式全解(四)日期和時間函式SQLServer函式