Delphi Clinic C++Builder Gate Training & Consultancy Delphi Notes Weblog Dr.Bob's Webshop
Dr.Bob's Delphi Notes Dr.Bob's Delphi Clinics
 Dr.Bob on Delphi 4 Year 2000 "pivot"
See Also: Delphi Papers and Columns

Borland Delphi 4 features a number of Object Pascal language enhancements, as usual. In this article, I'll address special support for the year 2,000 namely the TwoDigitYearCenturyWindow.

Year 2,000
Of course, everybody knows that the upcoming year 2,000 might cause some problems when it comes to interpreting dates such as 11/7/29. Is the above a date-of-birth of my father? Or is it the day I turn 65 (and await my retirement)? In this case, it's the latter. In fact, for this particular application I'm building, we can expect any year before "40" to be a "retirement starter" and not a birthday (simply because the application only stores "first work days" and "retirement days" (when someone turns 65) and not actual birthdays).
It would be nice to have some automatic support to tell functions like StrToDate, that 11/7/29 is somewhere in the 21st Century, while 26/10/89 is still in the 20th Century (the day I started to work for Bolesian - note that retirement isn't automatically exactly "40 years after", but it does start the day you turn 65 years of age - at least in The Netherlands).
And Delphi 4 now offers this support with the SysUtils global variable TwoDigitYearCenturyWindow.

TwoDigitYearCenturyWindow
TwoDigitYearCenturyWindow specifies how your application should interpret a 2-digit year. With the default value of TwoDigitYearCenturyWindow being 0, any year between 00 and 99 is assumed to be in the current century. If we give TwoDigitYearCenturyWindow a value of, say, 10, then this defines a "pivot" year at "the current year minus 10", which is 1988. Anything before 88 is now interpreted as being in the next century, while anything between 88 and 99 is still in this century.
Of course, 88 is not of much use, but 40 is (in the example above), and for that I need a TwoDigitYearCenturyWindow of 58, so anything before "40" is considered to be in next century:

  program Delphi4;
  uses
    SysUtils, Dialogs;
  const
    Retirement = '11/7/29';
  var
    DaysToGo: Double;
  begin
    ShortDateFormat := 'M/D/YYYY';
    TwoDigitYearCenturyWindow := 58; { everything before 40 is 20xx }
    DaysToGo := StrToDate(Retirement) - Date;
    ShowMessage(Format('%d days to go until %s',
               [Round(DaysToGo),
                DateToStr(StrToDate(Retirement))]))
  end.
This application nicely tells me how many days to go until my retirement...


This webpage © 2000-2015 by Bob Swart (aka Dr.Bob - www.drbob42.com). All Rights Reserved.