HOWTO: Prepare for the Year 2000Last reviewed: March 20, 1998Article ID: Q162388 |
3.00 3.00b 5.00 | 2.50b 2.60 2.60a | 2.50c 2.60a 3.00b | 2.60
WINDOWS | MS-DOS | MACINTOSH | UNIXkbusage kbhowto The information in this article applies to:
SUMMARYAs the millenium approaches, end users and developers need to consider the effect of the year 2000 on date recording, storage, and representation, and date calculations in current and new applications. This article discusses the condition of dates data in existing tables, and the steps to consider when you adjust applications in preparation for the year 2000. It also explains how to use the Visual FoxPro 5.0 "Set Century To" value and "Rollover" clause, and the aspects of using a class to control all environment variables in a project.
MORE INFORMATIONFoxPro tables store the actual contents of date data-type fields with a four-digit year value. Unless the application actually stored some other century, existing dates are stored as 19xx where xx is the two-digit year representation. Date calculations use this four-digit value for year. Presentation of a year value in a screen, form, or report depends on the Century setting. The default is for two-digits for year, or Off. To force the presentation of the entire four-digit value for year, the application must include the command Set Century On or the environment must have already been set by a similar command issued elsewhere. To illustrate this, in the command window of any version of FoxPro or Visual FoxPro type the following commands:
CREATE TABLE testyear (year d) APPEND BLANK BROWSEAn empty field appears. In this field, type in a date in the format mmddyy, such as 040197. The date appears as 04/01/97. In the command window type the following command:
SET CENTURY ONClick the title bar of the browse window, and notice that the presentation of the date changes to 04/01/1997. Type the following command:
SET CENTURY OFFClick the title bar of the browse window, and notice that the date changes to 04/01/97. Present FoxPro tables have the data necessary to carry existing applications into the new millenium. However, if screens (in applications developed for FoxPro) and forms (in applications developed for Visual FoxPro) were created with the environment setting of Century as Off, the @...GET and Textbox data entry controls accept only the last two digits of the year. If the person typing in data starts to type the year as 19xx, the 19 is accepted as year 1919. The program code needs to test for such values in the Valid procedure event or Lostfocus event. To prepare for the correct entry of dates when the year changes to 2000 or later, current applications probably need to be changed so that the full four-digit year value is entered when data is recorded. This may require the following:
Many developers start a project with a program that records and saves all environment settings, resets them to the ones required for the current application, and then resets them again to the original values at the conclusion of the application session. The environment settings are usually stored in the Foxuser.dbf table, but that table can be lost through corruption or other causes. A proactive approach to controlling the Century setting and all other pertinent environment variables is part of good application design.
The "Set Century To" Value and Rollover Clause in Visual FoxPro 5.0Visual FoxPro for Windows version 5.0 introduces the new "To" and "Rollover" clauses in the Set Century command. The Help file shows the following:
SET CENTURY ON SET CENTURY TO 19 && the value can range from 1 to 99 ? {02/16/56} && displays 02/16/1956 SET CENTURY TO 20 ? {01/16/56} && displays 02/16/2056The Rollover clause specifies a year above which is the current century, and below which is the next century. The following illustrates the use of this clause.
SET CENTURY ON SET CENTURY TO 19 ROLLOVER 60 ? {02/16/96} && Displays 02/16/1996 ? {02/16/56} && Displays 02/16/2056Again, the Help topic says that Set Century is scoped to the current data session. This emphasizes that the developer is responsible for proactively controlling the Century setting through code in the initial stages of the application. In Visual FoxPro a very convenient way of establishing the desired settings is to use a class that you can drop into every project.
Using A Class to Control All Environment VariablesYou can use the tsgen.vcx class library that is included as the Environment class with the Tastrade application as an example (it can be used "as is"). While this class includes code in the init, set, and reset events, it does not include how to control the Century setting. That would have to be added to the three event methods in order to be part of the class. Follow these steps in Visual FoxPro 5.0 to see the code for this class:
MODIFY CLASS environment OF SYS(2004)+"\SAMPLES\MAINSAMP\LIBS\TSGEN.VCX"On the View menu, click Code. For more information about using dates in calculations please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q130444 TITLE: How to Calculate the Years, Months, and Days Between Two Dates(c) Microsoft Corporation 1997, All Rights Reserved. Contributions by Chris Jensen, Microsoft Corporation
|
KBCategory: kbusage kbhowto
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |