db2 处理linux时间戳,DB2日期—时间—时间戳的运算

1、日期值的运算。

在日期上增加或者减去年,月,日时,可直接在增加或者减少的值后面直接跟着年月日的英文单词,

即year,month,day;大于1则使用复数形式,如下:

values (current date,             --2013-03-26(current_date)

current date + 10 years,  --2023-03-26

current date - 13 years,  --2000-03-26

current date + 13 months, --2014-04-26

current date - 24 months, --2011-03-26

current date + 60 days,   --2013-05-25

current date - 26 days    --2013-02-28

)

2、时间运算

在指定时间值上面增加或者减去时分秒值,在增减数据值后面跟着:hour,minute,second。

values (current_time,              --18:59:54

current_time + 10 hours,   --04:59:54

current_time - 23 hours,   --19:59:54

current_time + 12 minutes, --19:11:54

current_time - 63 minutes, --17:56:54

current_time + 25 seconds, --19:00:19

current_time - 61 seconds  --18:58:53

)

需要说明的是,当增加或者减少的数值为浮点数的时候,只会计算整数部分,

小数部分不会影响之后的运算,先后顺序:年 -> 月 -> 日 -> 时 -> 分 -> 秒

3、时间戳的运算

综合了第1点和第2点的运算。

values (current_timestamp,                  --2013-03-26-19.47.52.414000

current_timestamp + 10.5 years,     --2023-03-26-19.47.52.414000

current_timestamp - 4 months,       --2012-11-26-19.47.52.414000

current_timestamp + 26 days,        --2013-04-21-19.47.52.414000

current_timestamp + 7 hours,        --2013-03-27-02.47.52.414000

current_timestamp - 5.2 minutes,    --2013-03-26-19.42.52.414000

current_timestamp - 1 second,       --2013-03-26-19.47.51.414000

current_timestamp + 10 microseconds --2013-03-26-19.47.52.414010

)

4、若不考虑闰年,每月按照30天计算的话,可以使用timestampdiff()函数,详情请参照:

http://blog.csdn.net/bobo12082119/article/details/8724583

http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/topic/com.ibm.db2.luw.sql.ref.doc/doc/r0000861.html

转载请注明出处:http://blog.csdn.net/bobo12082119/article/details/8724586

--the end--

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值