【讨论】关于add_months

[复制链接]
查看11 | 回复9 | 2010-10-8 09:34:02 | 显示全部楼层 |阅读模式
select add_months(to_date(20140228,'yyyymmdd'),-1) from dual
想要得到1月28,怎么得到1月31号了,怎么解决

回复

使用道具 举报

千问 | 2010-10-8 09:34:02 | 显示全部楼层
ADD_MONTHS returns the date date plus integer months. A month is defined by the session parameter NLS_CALENDAR. The date argument can be a datetime value or any value that can be implicitly converted to DATE. The integer argument can be an integer or any value that can be implicitly converted to an integer. The return type is always DATE, regardless of the data type of date. If date is the last day of the month or if the resulting month has fewer days than the day component of date, then the result is the last day of the resulting month. Otherwise, the result has the same day component as date.
回复

使用道具 举报

千问 | 2010-10-8 09:34:02 | 显示全部楼层
赞2#
回复

使用道具 举报

千问 | 2010-10-8 09:34:02 | 显示全部楼层

赞2#
回复

使用道具 举报

千问 | 2010-10-8 09:34:02 | 显示全部楼层
那要同期的数据怎么写


回复

使用道具 举报

千问 | 2010-10-8 09:34:02 | 显示全部楼层
hisongy 发表于 2014-11-6 17:06
那要同期的数据怎么写

截取add_months的返回年月,再拼上原来的‘28’
回复

使用道具 举报

千问 | 2010-10-8 09:34:02 | 显示全部楼层
add_months不适合lz的需求。。。
回复

使用道具 举报

千问 | 2010-10-8 09:34:02 | 显示全部楼层
28日前都是准的
回复

使用道具 举报

千问 | 2010-10-8 09:34:02 | 显示全部楼层
hisongy 发表于 2014-11-6 17:06
那要同期的数据怎么写

若之前是1月31日,那2月的同期该怎么定义?
回复

使用道具 举报

千问 | 2010-10-8 09:34:02 | 显示全部楼层
ADD_MONTHS函数将一个日期上加上一指定的月份数,所以,日期中的日将是不变的。然而,如果开始日期是某月的最后一天,那么,结果将会调整以使返回值仍对应新的一月的最后一天。如果,结果月份的天数比开始月份的天数少,那么,也会向回调整以适应有效日期。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行