获取当前日期: 
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);

--获取当前日 
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;

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

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')));

 
例子:
select * from wx_account where date(opendate)='2012-04-22';

db2时间函数的更多相关文章

  1. DB2时间函数 实现 时间加减

    时间加减:后边记得跟上时间类型如day.HOUR TIMESTAMP ( TIMESTAMP(DEF_TIME)+1 day)+18 HOUR   DB2时间函数是我们最常见的函数之一,下面就为您介绍 ...

  2. DB2日期和时间函数汇总

    上一篇提到过在DB2中,可以通过SYSIBM.SYSDUMMY1.SYSIBM.DUAL获取寄存器中的值,也可以通过VALUES关键字获取寄存器中的值.则在这篇中,我们直接用VALUES关键字来看看这 ...

  3. DB2 日期时间函数

    db2日期时间函数 (DATE(TRIM(CHAR(DT#11Y))||'-'||TRIM(CHAR(DT#11M))||'-'||TRIM(CHAR(DT#11D))) BETWEEN DATE(' ...

  4. [转]DB2时间类函数

    Src URL:http://www.cnblogs.com/wanghonghu/archive/2012/05/25/2518604.html 1.db2可以通过SYSIBM.SYSDUMMY1. ...

  5. SQL 必备- ORACLE-SQSLSERVER-DB2时间函数及常见函数总结

    SQLSERVER 篇: 一.时间函数 --getdate 获取当前时间 select getdate() --dateadd 原有时间加: 2013-02-17 13:20:16 此时间加12个月 ...

  6. db2 OLAP函数使用

    说起 DB2 在线分析处理,可以用很好很强大来形容.这项功能特别适用于各种统计查询,这些查询用通常的SQL很难实现,或者根本就无发实现.首先,我们从一个简单的例子开始,来一步一步揭开它神秘的面纱,请看 ...

  7. DB2 OLAP函数的使用

    说起 DB2 在线分析处理,可以用很好很强大来形容.这项功能特别适用于各种统计查询,这些查询用通常的SQL很难实现,或者根本就无发实现.首先,我们从一个简单的例子开始,来一步一步揭开它神秘的面纱,请看 ...

  8. C++中的时间函数

    C++获取时间函数众多,何时该用什么函数,拿到的是什么时间?该怎么用?很多人都会混淆. 本文是本人经历了几款游戏客户端和服务器开发后,对游戏中时间获取的一点总结. 最早学习游戏客户端时,为了获取最精确 ...

  9. 借助JavaScript中的时间函数改变Html中Table边框的颜色

    借助JavaScript中的时间函数改变Html中Table边框的颜色 <html> <head> <meta http-equiv="Content-Type ...

随机推荐

  1. HDU5124:lines(线段树+离散化)或(离散化思想)

    http://acm.hdu.edu.cn/showproblem.php?pid=5124 Problem Description John has several lines. The lines ...

  2. Linux系统——公网定制化yum仓库部署

    1)搭建公网源yum仓库 安装wget aliyun源 # wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel ...

  3. #C++初学记录(并查集)

    并查集 题目 今天是伊格那丢的生日.他邀请了很多朋友.现在该吃晚饭了.伊格那丢想知道他至少需要多少张桌子.你必须注意到并不是所有的朋友都认识对方,而且所有的朋友都不想和陌生人待在一起.这个问题的一个重 ...

  4. poj1151 Atlantis && cdoj 1600艾尔大停电 矩形面积并

    题目: Atlantis Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23758   Accepted: 8834 Des ...

  5. Python 字符串转换为日期

    应用程序接受字符串格式的输入,但是你想将它们转换为datetime 对象以便在上面执行非字符串操作. 使用Python 的标准模块datetime 可以很容易的解决这个问题.比如: >>& ...

  6. PHImageManager 获取图片模糊

    PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init]; options.synchronous = true; o ...

  7. pyDay17

    1.用filter求素数. 埃拉托色尼筛选法. #!/usr/bin/env python3 # -*- coding: utf-8 -*- def _odd_iter(): n = 1 while ...

  8. SNMP Introduction

    Basic command of SNMP: GET: The GET operation is a request sent by the manager to the managed device ...

  9. Django:表结构发生变化需要执行命令

    Django:表结构发生变化需要执行命令 Django:表结构发生变化需要执行命令 mysite> python manage.py makemigrations blog #让 Django ...

  10. 20145322何志威《网络对抗》Exp2 后门原理与实践

    基础问题回答 1 例举你能想到的一个后门进入到你系统中的可能方式? 在网上下载盗版软件时捆绑的后门程序. 不小心进入钓鱼网站. 2 例举你知道的后门如何启动起来(win及linux)的方式? Wind ...