HOWTO: Prepare for the Year 2000

Last reviewed: March 20, 1998
Article 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         | UNIX
kbusage kbhowto

The information in this article applies to:

  • Microsoft Visual FoxPro for Windows, versions 3.0, 3.0b, 5.0
  • Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, 2.5a, 2.5b, 2.6, 2.6a
  • Microsoft Visual FoxPro for Macintosh, version 3.0b
  • Microsoft FoxPro for UNIX, version 2.6
  • Microsoft FoxPro for Windows, versions 2.5, 2.5a, 2.5b, 2.6, 2.6a
  • Microsoft FoxPro for Macintosh, versions 2.5b, 2.5c, 2.6a

SUMMARY

As 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 INFORMATION

FoxPro 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
   BROWSE

An 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 ON

Click 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 OFF

Click 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:

  1. Adjusting the width of the @...GET or Textbox controls so that the full value can be entered and seen.

  2. Modifying the presentation of dates in reports.

Also, you need to set the Century setting to On (either in the Setup procedure of a FoxPro screen, the Init event of a Form, the Main program of a project, or some other place where this value is initialized before you use the Century setting).

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.0

Visual 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/2056

The 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/2056

Again, 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 Variables

You 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:

  1. On the Help menu, click Sample Applications.

  2. Click the Open jump for the Tasmanian Traders sample to open the Tastrade project.

  3. In the Project Manager dialog box, click the Classes tab and select the tsgen library. Highlight the Environment class and click Modify.

  4. When the class appears in the Class Designer, right-click it and select Code from the context menu.

The same class may be found in Visual FoxPro 3.0 and 3.0b in the Vfp\Samples\Mainsamp\Libs\Tsgen.vcx library. You can see the environment class by typing the following command:

   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
KBSubcategory: FxenvFoxuser FxotherGeneral FxprgTable FxprgSet
Additional reference words: 3.00 3.00b 5.00 2.50b 2.60 2.60a 2.50c vfoxwin
vfoxmac foxwin foxmac foxdos kbdsd
Keywords : FxenvFoxuser FxotherGeneral FxprgSet FxprgTable kbhowto kbusage
Version : 3.00 3.00b 5.00 | 2.50b 2.60 2.6
Platform : MACINTOSH MS-DOS UNIX WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 20, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.