• DB2时间函数大全_时间加减


    时间加减:后边记得跟上时间类型如day、HOUR

    TIMESTAMP ( TIMESTAMP(DEF_TIME)+1 day)+18 HOUR

    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'))); 
  • 相关阅读:
    【数据结构】算法 Minimum Remove to Make Valid Parentheses 移除无效的括号
    【数据结构】算法 Remove Outermost Parentheses 删除最外层的括号
    【数据结构】算法 Valid Parentheses 有效的括号
    for嵌套的那些事
    i++与++i的区别
    初次接触JS 2017/11/27
    鼠标经过图片变大
    bootstrap使用
    ajax的应用原理及基本用法
    ajax实例代码及效果
  • 原文地址:https://www.cnblogs.com/wangpei/p/2349263.html
Copyright © 2020-2023  润新知