DB2数据库中时间函总结

数据库
本文将为您详细介绍DB2数据库中时间函数的分类介绍,供您参考,希望能对您有所帮助。

本文将为您详细介绍DB2数据库中时间函数的分类介绍,供您参考,希望能对您有所帮助。

DB2时间函数简单总结:

代码
--获取当前日期:

select current date from sysibm.sysdummy1;
values current date;

--获取当前日期
select current time from sysibm.sysdummy1;
values current time;
--获取当前时间戳
select current timestamp from sysibm.sysdummy1;
values current timestamp;

--要使当前时间或当前时间戳记调整到 GMT/CUT,则把当前的时间或时间戳记减去当前时区寄存器:

values current time -current timezone;
values current timestamp -current timezone;

--获取当前年份

values year(current timestamp);

--获取当前月
values month(current timestamp);#p#

--获取当前日
values day(current timestamp);

--获取当前时
values hour(current timestamp);

--获取分钟
values minute(current timestamp);

--获取秒
values second(current timestamp);

--获取毫秒
values microsecond(current timestamp);

--从时间戳记单独抽取出日期和时间

values date(current timestamp);
values VARCHAR_FORMAT(current TIMESTAMP,"yyyy-mm-dd");
values char(current date);
values time(current timestamp);

--执行日期和时间的计算

values current date+1 year;   
values current date+3 years+2 months +15 days;
values current time +5 hours -3 minutes +10 seconds;

--计算两个日期之间的天数#p#

values days(current date)- days(date("2010-02-20"));

--时间和日期换成字符串

values char(current date);
values char(current time);

--要将字符串转换成日期或时间值

values timestamp("2010-03-09-22.43.00.000000");
values timestamp("2010-03-09 22:44:36");
values date("2010-03-09");
values date("03/09/2010");
values time("22:45:27");
values time("22.45.27");

--计算两个时间戳记之间的时差:

--秒的小数部分为单位
values timestampdiff(1,char(current timestamp - timestamp("2010-01-01-00.00.00")));
--秒为单位
values timestampdiff(2,char(current timestamp - timestamp("2010-01-01-00.00.00")));
--分为单位
values timestampdiff(4,char(current timestamp - timestamp("2010-01-01-00.00.00")));
--小时为单位
values timestampdiff(8,char(current timestamp - timestamp("2010-01-01-00.00.00")));
--天为单位
values timestampdiff(16,char(current timestamp - timestamp("2010-01-01-00.00.00")));
--周为单位
values timestampdiff(32,char(current timestamp - timestamp("2010-01-01-00.00.00")));
--月为单位
values timestampdiff(64,char(current timestamp - timestamp("2010-01-01-00.00.00")));
--季度为单位
values timestampdiff(128,char(current timestamp - timestamp("2010-01-01-00.00.00")));
--年为单位
values timestampdiff(256,char(current timestamp - timestamp("2010-01-01-00.00.00")));

责任编辑:段燃 来源: 百维信息科技
相关推荐

2011-03-15 11:19:45

DB2数据库catalog

2010-09-01 10:17:14

DB2日志

2011-08-18 19:10:27

DB2数据库命令

2010-08-25 10:50:48

DB2数据库

2011-03-11 16:02:03

DB2数据库安装

2010-09-01 15:23:59

DB2字段类型

2010-11-01 11:30:41

DB2数据库权限

2010-11-03 16:21:18

DB2数据库授权

2010-08-26 16:15:25

DB2数据库管理

2010-09-30 11:49:21

DB2数据库权限

2009-07-06 17:34:26

远程复制DB2

2010-07-28 11:05:57

DB2数据库

2010-11-01 14:19:20

DB2字符串

2010-08-11 08:39:57

DB2 数据库

2010-08-26 16:34:12

DB2Excel读取

2010-08-31 11:26:59

DB2数据库

2010-08-31 13:06:49

DB2数据库

2010-11-02 11:49:18

SQL SERVER连

2010-11-03 16:32:10

DB2创建数据库

2010-09-06 10:00:00

DB2数据库
点赞
收藏

51CTO技术栈公众号