获取当前日期: 
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. python操作mysql数据库读取一个数据库的表写入另一个数据库

    写这个肯定是工作需要了,不啰嗦,直接说事 我现在有两台主机,一台是公司主机,一台是客户主机,要求把公司主机上的三个表同步到客户主机上的数据库 注意是同步,首先就得考虑用linux定时任务或者主从复制, ...

  2. uchome登录验证

    Uchome采用cookie+数据库的方式来进行用户登录验证的 一.登录 1:登录表单由source/do_login.php 处理 2:然后验证用户名以及密码的正确性,不正确则跳转并提示登录失败 3 ...

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

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

  4. POJ1006——Biorhythms(中国剩余定理)

    Biorhythms Description人生来就有三个生理周期,分别为体力.感情和智力周期,它们的周期长度为23天.28天和33天.每一个周期中有一天是高峰.在高峰这天,人会在相应的方面表现出色. ...

  5. Nodepad++ 资料整理

    http://www.crifan.com/files/doc/docbook/rec_soft_npp/release/webhelp/use_sbracket_lite_autocomplete_ ...

  6. Android初体验之Monkey和MonkeyRunner

    原文地址https://blog.csdn.net/mad1989/article/details/38087737 Monkey 什么是Monkey Monkey是Android中的一个命令行工具, ...

  7. hdu5139

    这题需要我们计算 这个 因为n<10000000空间过大 那么我们可以计算出 当n可以被10整除的时候我们就将n/10记录下来当我们要查询的时候去暴力计算他们与整十之间的数去暴力去做就好了 这个 ...

  8. 两个星期,用Flutter撸个APP

    前言 Flutter是Google推出的跨平台的解决方案,Slogan是"Design beautiful apps",国内也有知名企业在使用和推广,例如阿里.美团都有在尝试. 个 ...

  9. ng-深度学习-课程笔记-14: 人脸识别和风格迁移(Week4)

    1 什么是人脸识别( what is face recognition ) 在相关文献中经常会提到人脸验证(verification)和人脸识别(recognition). verification就 ...

  10. fiddler抓包HTTPS配置及代理设置

    使用fiddler抓包过程中遇到一系列的问题,浪费了大半天时间~~~写下解决办法 按照网上方法配置之后还是无法抓到cookies提示各种证书错误 1.卸载fiddler重新安装,设置 2.设置步骤 ( ...