本文介绍了通知框中的功能添加月份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个将当前日期添加到1个月的函数.我这样做:

I need a function that adds the current date to 1 month.I do so:

let _date =     MDY(MONTH(current_date)+1, DAY(current_date), YEAR(current_date));

但是在< 31

But there is a problem with the months in which the days <31

推荐答案

您需要检查它是否在您的版本中有效,但是如果您具有足够现代的Informix版本(11.70. FC5或更高版本,或12.10.FC1或更高版本),并且您使用DATETIME算术.

You'll need to check whether it works in your version, but you should get the result you want if you have a sufficiently modern version of Informix (11.70.FC5 or later, or version 12.10.FC1 or later) and you use DATETIME arithmetic.

LET next_month = EXTEND(current_date, YEAR TO DAY) + 1 UNITS MONTH

如果日期超出目标月份的范围,则较旧的Informix版本将被取消.

Older versions of Informix will baulk if the day is out of range for the target month.

在12.10服务器上进行测试,我使用了以下SQL:

Testing on a 12.10 server, I used this SQL:

create table dl (dv date not null primary key);
insert into dl values('2012-01-28');
insert into dl values('2012-01-29');
insert into dl values('2012-01-30');
insert into dl values('2012-01-31');
insert into dl values('2012-02-01');

SELECT dv, EXTEND(dv, YEAR TO DAY) + 1 UNITS MONTH FROM dl;

鉴于我在环境中设置了DBDATE=Y4MD-运行,输出为:

Given that I run with DBDATE=Y4MD- set in my environment, the output was:

2012-01-28    2012-02-28
2012-01-29    2012-02-29
2012-01-30    2012-02-29
2012-01-31    2012-02-29
2012-02-01    2012-03-01

这是使用12.10.FC5版本进行的测试.我可以确认,使用11.70.FC4,在2012年1月30日增加1个月时出现错误.我在将此答案写到答案中的同时查看了代码;它在2012年3月针对11.70修订包进行了修复. AFAICT,签入后的第一个修订包是11.70.FC5.因为您拥有11.70.FC3,所以产品中仍然保留了旧的行为(大约是1990年的一个设计决定,而不是一个错误).

This was testing with a 12.10.FC5 version. I can confirm that with 11.70.FC4 I get an error on the addition of 1 month to 2012-01-30. I reviewed the code while writing this addendum to my answer; it was fixed in March 2012 for an 11.70 fixpack. AFAICT, the first fix pack after the check in was 11.70.FC5. Since you have 11.70.FC3, the old behaviour — a deliberate design decision from circa 1990, not a bug per se — was still in the product.

这篇关于通知框中的功能添加月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 14:05