KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: SET DEFAULT CENTURY
PRODUCT: 4D | VERSION: 6.5 | PLATFORM: Mac & Win
Published On: January 7, 2000

Now that the year 2000 is here we are getting a few issues that some people did not think about. Now if you enter 4/14/00 you might get the year 4/14/1900 not 2000 as you expected. This is not a Y2K bug. This was the whole reason for the 4D V6 command SET DEFAULT CENTURY. This command allows you to set not only the century but a pivot year as well. Using this command we can get a one hundred year range on any group of one hundered years you choose. 1/1/25 - 12/31/24 can be 1/1/1925 - 12/31/2024; 1/1/2025 - 12/31/2124 or even 1/1/1795 - 12/31/1824 if you choose. All done with only two digit entries.

Please remember when using SET DEFAULT CENTURY you are setting CENTURYs not years.

Using the command as:

SET DEFAULT CENTURY(2000) will yield very strange results. (After all you are now talking about the year 200,000! I don't know about your operating system but mine is not prepared for that date yet.)

In order to obtain a range of years that will allow two digit year entry you might try something like:

On Startup

$LCentury:=Num(Substring(String(Year of(Current date));1;2))
$LYear:=Num(Substring(String(Year of(Current date));3))

If($LYear+10<100)
SET DEFAULT CENTURY($LCentury-1;$LYear+10)
Else
SET DEFAULT CENTURY($LCentury;$LYear+10-100)
End if

This will allow you to enter dates in two digits in the range of 89 years ago till 10 years in the future. (At least until the year 9998 Then somebody will have to modify your code.)

You can change the number of years into the future by changing all the 10s above to what ever number of year you would like.

This command requires 4D V6.0.x or above.

Special note: The default century for 4D is set to 19. It does not change to 20 just because it is now 2000. If you have NOT used the SET DEFAULT CENTURY command and you enter 1/4/00 you will get the year 1/4/1900 not 1/4/2000.

No good 4D V6.0 or above database should be without this command. Try it. You'll like it.