博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
DB2时间函数大全
阅读量:4519 次
发布时间:2019-06-08

本文共 2673 字,大约阅读时间需要 8 分钟。

DB2时间函数是我们最常见的函数之一,下面就为您介绍一些时间函数,供您参考,希望可以让您对DB2时间函数有更多的了解。

1 --获取当前日期:   2   3 select current date from sysibm.sysdummy1;    4 values current date;   5   6 --获取当前日期    7 select current time from sysibm.sysdummy1;    8 values current time;    9 --获取当前时间戳   10 select current timestamp from sysibm.sysdummy1;   11 values current timestamp;   12  13 --要使当前时间或当前时间戳记调整到 GMT/CUT,则把当前的时间或时间戳记减去当前时区寄存器:  14  15 values current time -current timezone;   16 values current timestamp -current timezone;   17  18 --获取当前年份  19  20 values year(current timestamp);  21  22 --获取当前月   23 values month(current timestamp);  24  25 --获取当前日   26 values day(current timestamp);  27  28 --获取当前时   29 values hour(current timestamp);  30  31 --获取分钟   32 values minute(current timestamp);  33  34 --获取秒   35 values second(current timestamp);  36  37 --获取毫秒   38 values microsecond(current timestamp);   39  40 --从时间戳记单独抽取出日期和时间  41  42 values date(current timestamp);   43 values VARCHAR_FORMAT(current TIMESTAMP,'yyyy-mm-dd');   44 values char(current date);   45 values time(current timestamp);   46  47 --执行日期和时间的计算  48  49 values current date+1 year;      50 values current date+3 years+2 months +15 days;   51 values current time +5 hours -3 minutes +10 seconds;   52  53 --计算两个日期之间的天数  54  55 values days(current date)- days(date('2010-02-20'));   56  57 --时间和日期换成字符串  58  59 values char(current date);   60 values char(current time);   61  62 --要将字符串转换成日期或时间值  63  64 values timestamp('2010-03-09-22.43.00.000000');   65 values timestamp('2010-03-09 22:44:36');   66 values date('2010-03-09');   67 values date('03/09/2010');   68 values time('22:45:27');   69 values time('22.45.27');   70  71 --计算两个时间戳记之间的时差:  72  73 --秒的小数部分为单位   74 values timestampdiff(1,char(current timestamp - timestamp('2010-01-01-00.00.00')));   75 --秒为单位   76 values timestampdiff(2,char(current timestamp - timestamp('2010-01-01-00.00.00')));   77 --分为单位   78 values timestampdiff(4,char(current timestamp - timestamp('2010-01-01-00.00.00')));   79 --小时为单位   80 values timestampdiff(8,char(current timestamp - timestamp('2010-01-01-00.00.00')));   81 --天为单位   82 values timestampdiff(16,char(current timestamp - timestamp('2010-01-01-00.00.00')));   83 --周为单位   84 values timestampdiff(32,char(current timestamp - timestamp('2010-01-01-00.00.00')));   85 --月为单位   86 values timestampdiff(64,char(current timestamp - timestamp('2010-01-01-00.00.00')));   87 --季度为单位   88 values timestampdiff(128,char(current timestamp - timestamp('2010-01-01-00.00.00')));   89 --年为单位   90 values timestampdiff(256,char(current timestamp - timestamp('2010-01-01-00.00.00')));

 

转载于:https://www.cnblogs.com/yuanhui69/p/3969906.html

你可能感兴趣的文章
Ubuntu下安装 Mysql
查看>>
LeetCode--Reverse Integer
查看>>
PHP_APC+Ajax实现的监视进度条的文件上传
查看>>
计算机网络课堂笔记3.29
查看>>
word2vec----CBOW
查看>>
衰减学习率真的有用吗?
查看>>
ORACLE 建库过程总结
查看>>
Ogre1.8.1 Basic Tutorial 6 - The Ogre Startup Sequence
查看>>
构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(36)-文章发布系统③-kindeditor使用...
查看>>
c# Winform 开发分屏显示应用程序
查看>>
canvas刮奖
查看>>
qt下拖放(一)
查看>>
Linux后台运行python程序并输出到日志文件
查看>>
HTML的语义化和一些简单优化
查看>>
jQuery基础教程
查看>>
Spring 在xml文件中配置Bean
查看>>
poj1611(简答并查集)
查看>>
基于scap的服务器安全基线核查设计与实现
查看>>
NFS 安装与配置
查看>>
javascript 模拟滚动 隐藏滚动条
查看>>