互联网服务

日期的奇怪问题

db2 "select date(substr(char(date('2012-10-11')+1 month),1,8)||'01') -1 day from sysibm.sysdummy1"
本意是要取当月的最后一天,应该是2012-10-31,但结果是2001-11-29呢?
参与6

5同行回答

ppjava2009ppjava2009系统工程师用友汽车信息科技(上海)有限公司
找到问题,应该结贴啊!显示全部
找到问题,应该结贴啊!收起
互联网服务 · 2012-11-13
浏览578
tomthetomthe软件开发工程师zsbank
我找到原因了,是日期格式的问题,db2 "select date(substr(char(date('2012-10-11')+1 month,ISO),1,8)||'01') -1 day from sysibm.sysdummy1"就可以了,谢谢大家了。显示全部
我找到原因了,是日期格式的问题,db2 "select date(substr(char(date('2012-10-11')+1 month,ISO),1,8)||'01') -1 day from sysibm.sysdummy1"就可以了,谢谢大家了。收起
互联网服务 · 2012-11-08
浏览635
tomthetomthe软件开发工程师zsbank
但我的写为什么就不行呢?怎么解释啊,程序里都是这是这种写法,不知道会不会出问题的。显示全部
但我的写为什么就不行呢?怎么解释啊,程序里都是这是这种写法,不知道会不会出问题的。收起
互联网服务 · 2012-11-08
浏览629
ppjava2009ppjava2009系统工程师用友汽车信息科技(上海)有限公司
--获取本月最后一天values current timestamp + 1 months - day(current timestamp) days ;values current timestamp - day(current timestamp) days + 1 days + 1 months - 1 days ;values current timestamp + 1 months - day(current timestamp) days - hour(current...显示全部
--获取本月最后一天
values current timestamp + 1 months - day(current timestamp) days ;
values current timestamp - day(current timestamp) days + 1 days + 1 months - 1 days ;
values current timestamp + 1 months - day(current timestamp) days - hour(current timestamp) hours - minute(current timestamp) minutes - second(current timestamp) seconds - microsecond(current timestamp) microsecond ;
values current date + 1 months - day(current date + 1 months) days ;收起
互联网服务 · 2012-11-08
浏览587
wangyaxwangyax软件开发工程师金融机构
C:\Documents and Settings\wangyax>db2 "select date(substr('2011-10-11',1,8)||'01') + 1 month - 1 day from sysibm.sysdummy1"1----------2011-10-31  1 条记录已选择。显示全部
C:\Documents and Settings\wangyax>db2 "select date(substr('2011-10-11',1,8)||'01') + 1 month - 1 day from sysibm.sysdumm
y1"
1
----------
2011-10-31
  1 条记录已选择。收起
互联网服务 · 2012-11-07
浏览594

提问者

tomthe
软件开发工程师zsbank

问题状态

  • 发布时间:2012-11-07
  • 关注会员:1 人
  • 问题浏览:3438
  • 最近回答:2012-11-13
  • X社区推广