The information in this article applies to:
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.
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.
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:
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:
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:
In some cases, however, users enter only two digit dates to maximize data entry effort. In those cases, the developer can write custom code to intercept the date and change the century if needed before the data goes into the table. 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 and 6.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:
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.
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 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:
On the View menu, click Code.
For Visual FoxPro 6.0, type the following command:
On the View menu, click Code.
© Microsoft Corporation 1999, All Rights Reserved. REFERENCESFor additional information about using dates in calculations, click the article number below to view the article in the Microsoft Knowledge Base: Q130444 How to Calculate the Years, Months, and Days Between Two Dates Additional query words:
|
|
Last Reviewed: September 29, 1999 © 1999 Microsoft Corporation. All rights reserved. Terms of Use. |