Hola a tod@s,
Os dejo una función que he creado para evitar el error «The result of a datetime computation is out of range» que nos puede aparecer al intentar hacer una SQL en informix al tratar de sumar o restar meses o años a una fecha.
CREATE FUNCTION Add_datetime_interval
(dFecha DATE,
iIntervalo int,
bMeses BOOLEAN,
bRestar boolean) returning DATE as fecha
DEFINE dResult DATE;
DEFINE iDay INT;
DEFINE iMonth INT;
LET iDay = DAY(dFecha);
LET dResult = dFecha – (iDay – 1) UNITS DAY;
LET iMonth = MOD(MONTH(dFecha) + iIntervalo, 12) ;
IF NOT bMeses THEN
IF NOT bRestar THEN
LET dResult = dResult + iIntervalo UNITS YEAR;
ELSE
LET dResult = dResult – iIntervalo UNITS YEAR;
END IF
LET iMonth = MONTH(dResult + (iDay – 1) UNITS DAY);
ELSE
IF NOT bRestar THEN
LET dResult = dResult + iIntervalo UNITS MONTH;
ELSE
LET dResult = dResult – iIntervalo UNITS MONTH;
END IF
LET iMonth = MONTH(dResult + (iDay – 1) UNITS DAY);
END IF
IF iMonth <> MONTH(dResult) THEN
LET dResult = dResult + (iDay – 1) UNITS DAY;
LET iDay = DAY(dResult);
LET dResult = dResult – iDay UNITS DAY;
ELSE
LET dResult = dResult + (iDay – 1) UNITS DAY;
END IF
RETURN dResult;
END FUNCTION;
Espero que os ayude como a mi me ha servido.
Saludos.
Por Dios Carmen, esta muy bueno. Te amo, aunque estés lejos, te amo. Eres lo máximo.. Besos desde Venezuela.
Hola, Carmen es muy interesante esta nota, estoy tratando de llamar a un 4gi a traves de «fglgo», desde un «store» o una «function» sobre «informix» con el comando «system» y no logro hacerlo.
Tenes alguna idea de como hacer esto o si ya lo has intentado antes.
De todos modos gracias.
Saludos,
Juan
If you are willing to enlarge your knowledge referring to this good post, look for thesis writing or custom dissertation and order the best the dissertation there.