Re: forms30 and Y2K -- Sliding Century Function

From: Steve Cosner <stevec_at_zimmer.csufresno.edu>
Date: 3 Aug 1998 15:28:03 GMT
Message-ID: <6q4ku3$4e91_at_hendrix.csufresno.edu>


In article <6pspk2$e2q2_at_hendrix.csufresno.edu>, Steve Cosner <stevec_at_zimmer.csufresno.edu> wrote:

> I have a "sliding century" function that I used in Forms 3.0 (and
> now in Forms 4.5) to infer the correct century. -- it's better than
> RR, because it is date sensitive, and we use it almost everywhere in
> forms. The biggest problem is that you need to call it from every
> date validation trigger.
>
> I can email it or post it if anyone wants to see it.

Since several people asked for this, here it is:



A Century Function

From Steve Cosner, California State University, Fresno, California, USA. email: stevec_at_csufresno.edu

Here is a PL/SQL function which returns a valid century for any 2-digit year. Its behavior changes each year, so that it always works as expected. In most situations, users should NEVER need to enter a century.

It forces a date to contain a century within the range of 89 years BEFORE, and 10 years AFTER the current year. For example:   In 1997, if a user enters 01-JAN-08, the function   translates the year to 1908; in 1998, it translates   to 2008. Entering 31-DEC-05 translates to 2005; 01-JAN-99   translates to 1999.

The process continues to work forever.

FUNCTION CENTURYF (YY CHAR) RETURN CHAR IS

  • YY is the 2-digit year for which a century is returned. YR_YYYY NUMBER(4):=TO_NUMBER(TO_CHAR(SYSDATE,'YYYY'))-90;
  • In Oracle Forms, we store sysdate in the form in a
  • parameter or global variable, so it only needs to be
  • requested from the server once. BEGIN IF SUBSTR(YY,1,2) > SUBSTR(TO_CHAR(YR_YYYY),3,2) THEN RETURN SUBSTR(TO_CHAR(YR_YYYY),1,2); ELSE RETURN SUBSTR(TO_CHAR(YR_YYYY + 100),1,2); END IF; END;
    Set up another function to use CENTURYF above: FUNCTION FIXDATE (DATE_I DATE) RETURN DATE IS DATE_TMP DATE BEGIN Return To_Date(Centuryf(To_Char(Date_i,'YY')) ||To_Char(Date_I,'YYMMDD'), 'YYYYMMDD'); END;
    (You could combine the two functions above into one)
    Now, anywhere in your form you need the correct date, (For example, in a When-Validate-Item trigger) do this: :Block.Date_Item := Fixdate(:Block.Date_Item);
Received on Mon Aug 03 1998 - 17:28:03 CEST

Original text of this message