Year 2000 Date Support
Visual FoxPro was enhanced to provide better year 2000 date support. This section describes the enhancements made to Visual FoxPro to make it easier to create year 2000 compliant applications.
SET CENTURY TO
The documentation states that issuing SET CENTURY TO without additional arguments sets the century to the current century. This is only true in the 20th century, because the century is set to 19 regardless of the current century. Now in Visual FoxPro, SET CENTURY TO sets the century to the current century. Additionally, the value of SET CENTURY TO in new data sessions is initialized to the current century.
Also, Visual FoxPro, the default ROLLOVER value for SET CENTURY has changed to the last two digits of the current year plus 50 years - if the current year is 1998, nYear is 48, the last two digits of 2048 (1998 + 50).
See SET CENTURY for more information.
Strict Date Formats
Normally, Date and DateTime constants or expressions are interpreted based on the current settings of SET DATE and SET CENTURY at the time the constants or expressions are compiled or evaluated. This means that many date constants are ambiguous since they might evaluate to different values depending upon when they were compiled and what date settings were in effect at compilation time.
For example, is the date constant {10/11/12} October 11, 1912, October 11, 2012, November 10, 1912, November 12, 1910, or November 12, 2010?
It all depends on the current settings of SET DATE and SET CENTURY TO. This can introduce errors into existing Visual FoxPro code wherever Date or DateTime constants or expressions either are compiled or are evaluated at run time, such as in report and object expressions. This can introduce year 2000 noncompliance into existing code when the setting of SET CENTURY rolls over into the year 2000 and a four-digit year isn't specified.
To avoid noncompliance, a strict date format is now available in Visual FoxPro. A strict date always evaluates to the same Date or DateTime value regardless of any date settings. The strict date format is:
^yyyy-mm-dd[,][hh[:mm[:ss]][a|p]]
The caret character (^) always denotes the strict date format and causes Dates and DateTimes to be interpreted in a YMD format. Valid Date and DateTime separators are hyphens, forward slashes, periods, and spaces.
Empty Dates and DateTimes are considered nonambiguous and are always valid. Valid empty Date and DateTime formats include {}, { — }, and { — ,:}.
With strict date formats, a greater range of Date and DateTime values are available. In Visual FoxPro 5.0, the smallest date value that can be expressed is {^0100/1/1}, January 1, 100 A.D. This is because year values less than 100 were always rounded up to the nearest century based on the setting of SET CENTURY.
The smallest valid date in Visual FoxPro is {^0001-01-01}, January 1, 1 A.D. The largest valid date in Visual FoxPro is {^9999-12-31}, December 31, 9999 A.D.
Note that the strict date format ignores the TAIWAN setting for SET DATE, so the year of a strict format Date or DateTime is always in the Western calendar. (Note that this is not true in Visual FoxPro 5.0.)
SET STRICTDATE
A new command, SET STRICTDATE, can be used to enforce year 2000 compliant date constants and date strings.
SET STRICTDATE TO 0
Setting STRICTDATE to 0 means that strict date format checking is off. 0 is the default setting for the Visual FoxPro run time and ODBC driver. When STRICTDATE is set to 0, invalid Date and DateTimes evaluate to the empty date.
SET STRICTDATE TO 1
Setting STRICTDATE to 1 requires that all Date and DateTime constants be in the strict date format. Any Date or DateTime constant that is not in the strict format or evaluates to an invalid value generates an error, either during compilation, at run time, or during an interactive Visual FoxPro session. 1 is the default setting for an interactive Visual FoxPro session.
SET STRICTDATE TO 2
Identical to setting STRICTDATE to 1, but also generates a compilation error (2033 – CTOD and CTOT can produce incorrect results) whenever CTOD( ) and CTOT( ) functions appear in code.
Because the values returned by CTOD( ) and CTOT( ) rely on SET DATE and SET CENTURY to interpret the date string they contain, they are prone to year 2000 noncompliance errors. Use DATE( ) and DATETIME( ) with the optional numeric arguments to create Date and DateTime constants and expressions.
This setting is most useful during debugging sessions to trap for code that might contain year 2000 compliance errors.
Strict Date Format Errors
The following new errors were added to Visual FoxPro, and can be generated when SET STRICTDATE is set to 1 or 2.
Options Dialog
The General tab of the Options dialog box now includes a Year 2000 Compliance drop-down list box, which specifies the setting of SET STRICTDATE. Like all other Options dialog items, the value is set for the current Visual FoxPro session, and choosing Set As Default saves the setting to the Windows registry for the next Visual FoxPro session.
DATE( ) and DATETIME( ) Functions
The DATE( ) and DATETIME( ) functions now support optional numeric arguments that make it possible for you to create year 2000 compliant Date or DateTime values. The enhancements to these functions now provide a preferable method for creating Date and DateTime values; it's no longer necessary to use character manipulation functions to create Date and DateTime values.
FDATE( ) Function
The FDATE( ) function now supports an optional argument that makes it possible for you to determine the time when a file was last modified without using character manipulation functions. For example, in previous versions of Visual FoxPro, it was necessary to write code like the following to determine when the Visual FoxPro resource file was last modified:
tLastModified = CTOT(DTOC(FDATE('Foxuser.dbf')) + ' ' ;
+ FTIME('Foxuser.dbf')
This code can now be replaced with the following:
tLastModified = FDATE('Foxuser.dbf', 1)
Century Property
The default for the Century property in Visual FoxPro is 1 – On. The century portion of the date is displayed in a text box. In previous versions of Visual FoxPro, the default is 2 – the SET CENTURY setting determines if the century portion of the date is displayed.
See Also
Graphics Support in Visual FoxPro | Creating Access and Assign Methods | Access and Assign Methods | SET CENTURY | SET DATE