这里有一些旧代码有一段时间没有出现,但仍然是有效的 I4GL。
ltmonth.4gl
{
@(#)$Id: ltmonth.4gl,v 1.4 1990/04/05 11:02:05 john Exp $
@(#)Sphinx Informix Tools: General Library
@(#)Find last day of this month
@(#)Author: JL
}
FUNCTION last_of_this_month(edate)
DEFINE
edate DATE { Effective date (frequently TODAY) }
IF edate IS NULL THEN
RETURN edate
END IF
RETURN first_of_next_month(edate) - 1
END FUNCTION {last_of_this_month}
fnmonth.4gl
{
@(#)$Id: fnmonth.4gl,v 1.4 1990/04/05 11:02:03 john Exp $
@(#)Sphinx Informix Tools: General Library
@(#)Find 1st of next month
@(#)Author: JL
}
FUNCTION first_of_next_month(edate)
DEFINE
edate DATE, { Effective date (frequently TODAY) }
mm INTEGER, { Month number }
yy INTEGER { Year }
IF edate IS NULL THEN
RETURN edate
END IF
LET mm = MONTH(edate) + 1
LET yy = YEAR(edate)
IF mm > 12 THEN
LET mm = 1
LET yy = yy + 1
END IF
RETURN MDY(mm, 1, yy)
END FUNCTION {first_of_next_month}
lastthismonth.spl
下面是一些基于上述 I4GL 的 SPL:
-- @(#)$Id: lastthismonth.spl,v 1.2 2008/07/20 02:54:37 jleffler Exp $
--
-- @(#)Create last_of_this_month Stored Procedure
--
-- @(#)Version: ltmonth.4gl,v 1.4 1990/04/05 11:02:05 john
-- @(#)Sphinx Informix Tools: General Library
-- @(#)Find last day of this month
-- @(#)Author: JL
--
-- Alternative expression:
-- (MDY(MONTH(dateval), 1, YEAR(dateval)) + 1 UNITS MONTH) - 1 UNITS DAY
CREATE PROCEDURE last_of_this_month(edate DATE DEFAULT TODAY)
RETURNING DATE AS last_of_this_month;
IF edate IS NULL THEN
RETURN edate;
END IF
RETURN first_of_next_month(edate) - 1;
END PROCEDURE {last_of_this_month};
firstnextmonth.spl
-- @(#)$Id: firstnextmonth.spl,v 1.1 2008/07/20 02:21:13 jleffler Exp $
--
-- @(#)Create first_of_next_month Stored Procedure
--
-- @(#)Version: fnmonth.4gl,v 1.4 1990/04/05 11:02:03 john
-- @(#)Sphinx Informix Tools: General Library
-- @(#)Find 1st of next month
-- @(#)Author: JL
CREATE PROCEDURE first_of_next_month(edate DATE DEFAULT TODAY)
RETURNING INTEGER AS first_of_next_month;
DEFINE mm INTEGER; { Month number }
DEFINE yy INTEGER; { Year }
IF edate IS NULL THEN
RETURN edate;
END IF
LET mm = MONTH(edate) + 1;
LET yy = YEAR(edate);
IF mm > 12 THEN
LET mm = 1;
LET yy = yy + 1;
END IF
RETURN MDY(mm, 1, yy);
END PROCEDURE {first_of_next_month};
注意替代表达式。它有效,但它是 DATE 和 DATETIME 计算的令人难以置信的混合。