开发者

Oracle PL/SQL datetime math - intervals

I've been using syntax like {?EndDate} - INTERVAL '1' YEAR for a while now, and I knew开发者_高级运维 there was an issue that I was going to hit eventually, and I just hit it. I tried to do DATE '2010-12-31' - INTERVAL '6' MONTH, and it choked because there's no June 31st. What's the most efficient and consistent way to code this? While tracking down the person who made the decision to do it this way would be more satisfying, it's impractical. :-)


I am not sure if there is a constistent way, since it certainly depends on what someone thinks is 6 months. Yet, imho, it is safe to assume that add_months is a standard way (at least in Oracle) to subtract or add months:

select add_months(DATE '2010-12-31',-6)  from dual;

This expression returns June 30th 2010 (which is the last day in that month (as is the 31st in december).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜