DB2 常用日期SQL语句
2011-11-27 14:38
288 查看
--获取上个月末日期格式为yyyyMMdd
values current timestamp -day(current date) days
values ts_fmt(current timestamp -day(current date) days,'yyyymmdd')
--获取当前月份
values month(current date)
--获取本月的第一天
values current timestamp -day(current date) days+ 1 days
--获取本月的最后一天
values current timestamp+1 months -day(current date) days
--获取上月的第一天
values current timestamp -1 months-day(current date) days+ 1 days
--获取上月的最后一天
values current timestamp -day(current date) days
具体关于DB2日期文章 参考:http://www.ibm.com/developerworks/cn/data/library/techarticles/0211yip/0211yip3.html
values current timestamp -day(current date) days
values ts_fmt(current timestamp -day(current date) days,'yyyymmdd')
--获取当前月份
values month(current date)
--获取本月的第一天
values current timestamp -day(current date) days+ 1 days
--获取本月的最后一天
values current timestamp+1 months -day(current date) days
--获取上月的第一天
values current timestamp -1 months-day(current date) days+ 1 days
--获取上月的最后一天
values current timestamp -day(current date) days
--创建一个日期格式转换 create function ts_fmt(TS timestamp, fmt varchar(20)) returns varchar(50) return with tmp (dd,mm,yyyy,hh,mi,ss,nnnnnn) as ( select substr( digits (day(TS)),9), substr( digits (month(TS)),9) , rtrim(char(year(TS))) , substr( digits (hour(TS)),9), substr( digits (minute(TS)),9), substr( digits (second(TS)),9), rtrim(char(microsecond(TS))) from sysibm.sysdummy1 ) select case fmt when 'yyyymmdd' then yyyy || mm || dd when 'mm/dd/yyyy' then mm || '/' || dd || '/' || yyyy when 'yyyy/dd/mm hh:mi:ss' then yyyy || '/' || mm || '/' || dd || ' ' || hh || ':' || mi || ':' || ss when 'nnnnnn' then nnnnnn else 'date format ' || coalesce(fmt,' ') || ' not recognized.' end from tmp
具体关于DB2日期文章 参考:http://www.ibm.com/developerworks/cn/data/library/techarticles/0211yip/0211yip3.html
相关文章推荐
- DB2 常用日期SQL语句
- DB2 不常用SQL语句集合
- DB2中常用sql语句语法
- DB2中常用sql语句语法
- DB2比较常用与实用sql语句总结
- DB2 常用的SQL语句
- DB2中常用sql语句语法
- DB2比较常用与实用sql语句总结
- SQL“常用查询语句”、“常用日期查询方式”、“常用函数”整理
- 种子张的SQL教程(转)作者:blogcat 日期:2007-11-21 20:42:01 注:红色标识为常用语句(唉,写了一天了,那个累呀!) 转自种子张的博客
- SQL 日期截取? & 日期比较&日期查询常用语句
- 常用日期计算SQL语句
- oracle常用的修改表信息及其获取系统日期时间的sql语句
- 50个常用的sql语句
- MySQL的一些常用的SQL语句整理
- mysql常用的sql语句
- MySql常用SQL语句
- SQL常用的语句和函数
- Oracle SQL常用语句
- sql常用语句