DB2时间函数大全

系统 2306 0
      
        
          原文出处:http://database.51cto.com/art/201011/232578.htm
        
        

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时间函数大全


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论