informix常用时间运算和操作方法

本文转载于http://blog.itpub.net/70612/viewspace-1027846/

informix数据库中的时间运算

select first 1 today,current,current -1 units year,current -1 units day,current -1 units hour,current -1 units minute,current -1 units second from systables
select first 1 extend(current,year to day),extend(current,year to second),extend(current,year to year),extend(current,hour to second) from systables
select first 1 extend(current,year to day), extend(current,year to day) - 1 units day,extend(current,year to second),extend(current,year to year),extend(current,hour to second) from systables
select first 1 to_char(current,'%Y%m%d') from systables --Y大写和小写有区别,Y大写年份用4位数字,y小写年份用2位数字
select first 1 extend(to_date('20091015','%Y%m%d'),year to day) from systables
select first 1 day(current) from systables --直接取天
select first 1 date(current) from systables --取到天
select first 1 date(current) - interval(2) day to day from systables --当前日期减2天
select first 1 date(current) - interval(2) year to year from systables--当前日期减2年
select first 1 current,current - 2 units minute from systables --当前日期减2分钟
select first 1 current,date(current) - 2 units day,extend(date(current),year to minute) - 2 units minute from systables

总结
时间格式的字段可以直接和integer进行加减运算,需要注意的是加减运算的参与字段单位必须统一,例如 extend (year to minute)的最小单位是分钟,那么只能和分钟进行运算
例如
select first 1 current,date(current) - 2 units day,extend(date(current),year to minute) - 2 units minute from systables
而不能
select first 1 current,date(current) - 2 units day,extend(date(current),year to minute) - 2 units second from systables 会报错

today current类似于oracle的sysdate
informix的日期的format可以参考informix的global support GLS User's Guide
informix也有to_char() to_date()函数,当然跟oracle的用法完全不同[@more@]

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值