Re: Forms4.5: mm/dd/yyyy date format default
Date: 1997/07/21
Message-ID: <869500479.4314_at_dejanews.com>#1/1
In article <5qo1ae$5fq_at_atlantis.utmb.edu>,
cfischer_at_ancillary.utmrad1.utmb.edu (Cathy Fischer) wrote:
>
> In article <33CDAF88.DF2_at_public.srce.hr>, bbiljman_at_public.srce.hr says...
> >
> >Cathy Cantieri wrote:
> >>
> >> I put the format mm/dd/yyyy on an item and then when I enter 071697 and
> >> move off the field it is changing it to 07/16/0097. Why is it doing that?
> >> Why doesn't it make the century 19? Is there a way to make it make the
> >> century the current one?
> >
> > Try mm/dd/rrrr
>
> the rrrr isn't going to work for this particular field because it is date of
> birth and in 2001 we will still have people whose dob is before 1949 (at least
> I hope so! :) )
The problem with MM/DD/YYYY format is that you cannot enter 00 for a year. The form gives you an error. You can use MM/DD/RRRR format along with a when-validate-item trigger on the date, and change the century. I am including the code below that we use.
We have dropped using RRRR in any date format, because we have to support Macintosh Forms 4.5 where the RRRR format is not recognized. Because of this, we are going back to just using YY for the year format, and using the sliding century routine (below) to get the correct century.
The only drawback to using the sliding century routine is that it always runs, so your users can't enter anything outside the century deemed correct by the routine. On birthdates, you may just want to force the user to always enter the 4-digit century.
Steve Cosner
http://members.aol.com/stevec5088
QA: Dynamic browse & update utility form available
(upgraded to version 0.7e 05-May-1997)
The "Sliding Century" Function
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);
-------------------==== Posted via Deja News ====----------------------- http://www.dejanews.com/ Search, Read, Post to UsenetReceived on Mon Jul 21 1997 - 00:00:00 CEST