DB2时间函数大全
创始人
2024-07-17 03:50:08
0

DB2时间函数是我们最常见的函数之一,下面就为您介绍一些DB2时间函数,供您参考,希望可以让您对DB2时间函数有更多的了解。

  1. --获取当前日期:  
  2.  
  3. select current date from sysibm.sysdummy1;   
  4. values current date;  
  5.  
  6. --获取当前日期   
  7. select current time from sysibm.sysdummy1;   
  8. values current time;   
  9. --获取当前时间戳   
  10. select current timestamp from sysibm.sysdummy1;   
  11. values current timestamp;   
  12.  
  13. --要使当前时间或当前时间戳记调整到 GMT/CUT,则把当前的时间或时间戳记减去当前时区寄存器:  
  14.  
  15. values current time -current timezone;   
  16. values current timestamp -current timezone;   
  17.  
  18. --获取当前年份  
  19.  
  20. values year(current timestamp);  
  21.  
  22. --获取当前月   
  23. values month(current timestamp);  
  24.  
  25. --获取当前日   
  26. values day(current timestamp);  
  27.  
  28. --获取当前时   
  29. values hour(current timestamp);  
  30.  
  31. --获取分钟   
  32. values minute(current timestamp);  
  33.  
  34. --获取秒   
  35. values second(current timestamp);  
  36.  
  37. --获取毫秒   
  38. values microsecond(current timestamp);   
  39.  
  40. --从时间戳记单独抽取出日期和时间  
  41.  
  42. values date(current timestamp);   
  43. values VARCHAR_FORMAT(current TIMESTAMP,'yyyy-mm-dd');   
  44. values char(current date);   
  45. values time(current timestamp);   
  46.  
  47. --执行日期和时间的计算  
  48.  
  49. values current date+1 year;      
  50. values current date+3 years+2 months +15 days;   
  51. values current time +5 hours -3 minutes +10 seconds;   
  52.  
  53. --计算两个日期之间的天数  
  54.  
  55. values days(current date)- days(date('2010-02-20'));   
  56.  
  57. --时间和日期换成字符串  
  58.  
  59. values char(current date);   
  60. values char(current time);   
  61.  
  62. --要将字符串转换成日期或时间值  
  63.  
  64. values timestamp('2010-03-09-22.43.00.000000');   
  65. values timestamp('2010-03-09 22:44:36');   
  66. values date('2010-03-09');   
  67. values date('03/09/2010');   
  68. values time('22:45:27');   
  69. values time('22.45.27');   
  70.  
  71. --计算两个时间戳记之间的时差:  
  72.  
  73. --秒的小数部分为单位   
  74. values timestampdiff(1,char(current timestamp - timestamp('2010-01-01-00.00.00')));   
  75. --秒为单位   
  76. values timestampdiff(2,char(current timestamp - timestamp('2010-01-01-00.00.00')));   
  77. --分为单位   
  78. values timestampdiff(4,char(current timestamp - timestamp('2010-01-01-00.00.00')));   
  79. --小时为单位   
  80. values timestampdiff(8,char(current timestamp - timestamp('2010-01-01-00.00.00')));   
  81. --天为单位   
  82. values timestampdiff(16,char(current timestamp - timestamp('2010-01-01-00.00.00')));   
  83. --周为单位   
  84. values timestampdiff(32,char(current timestamp - timestamp('2010-01-01-00.00.00')));   
  85. --月为单位   
  86. values timestampdiff(64,char(current timestamp - timestamp('2010-01-01-00.00.00')));   
  87. --季度为单位   
  88. values timestampdiff(128,char(current timestamp - timestamp('2010-01-01-00.00.00')));   
  89. --年为单位   
  90. values timestampdiff(256,char(current timestamp - timestamp('2010-01-01-00.00.00'))); 

 

 

 

【编辑推荐】

DB2公共表表达式的用法

跨数据库访问DB2表的方法

DB2表空间大小的限制

深入解读DB2存储过程

DB2连接服务器的配置

相关内容

热门资讯

如何允许远程连接到MySQL数... [[277004]]【51CTO.com快译】默认情况下,MySQL服务器仅侦听来自localhos...
如何利用交换机和端口设置来管理... 在网络管理中,总是有些人让管理员头疼。下面我们就将介绍一下一个网管员利用交换机以及端口设置等来进行D...
施耐德电气数据中心整体解决方案... 近日,全球能效管理专家施耐德电气正式启动大型体验活动“能效中国行——2012卡车巡展”,作为该活动的...
Windows恶意软件20年“... 在Windows的早期年代,病毒游走于系统之间,偶尔删除文件(但被删除的文件几乎都是可恢复的),并弹...
20个非常棒的扁平设计免费资源 Apple设备的平面图标PSD免费平板UI 平板UI套件24平图标Freen平板UI套件PSD径向平...
德国电信门户网站可实时显示全球... 德国电信周三推出一个门户网站,直观地实时提供其安装在全球各地的传感器网络检测到的网络攻击状况。该网站...
着眼MAC地址,解救无法享受D... 在安装了DHCP服务器的局域网环境中,每一台工作站在上网之前,都要先从DHCP服务器那里享受到地址动...
为啥国人偏爱 Mybatis,... 关于 SQL 和 ORM 的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行...