1. Tech

Your suggestion is on its way!

An email with a link to:


was emailed to:

Thanks for sharing About.com with others!

RTL Reference|Glossary|Tips/Tricks|FREE App/VCL|Best'O'Net|Books|Link Back


Dateline: 05/18/99
Updated: 10/23/99

Do you know what will happen at midnight in the Year 2000?
You don't !? The World is going to collapse.
Or maybe not, if you know how to assure that your Delphi application doesn't contain the Millenium bug.

   Y2K in general
Many applications rely on date arithmetic. Since the beginning of computer/application programming it was a common practice to limit the storage of dates (usually involving use of a two-digit year) in order to save memory and disk space. With the arrival of the year 2000, these software applications will become incapable of correctly processing dates causing malfunctions in the way the programs use data.

   Is Delphi Y2K compliant?
Don't be lulled into a false sense of security just because you are using the latest version of Delphi which IS Y2K compliant. If you want to be sure that your Delphi application is Y2K compliant, all parts of the system must be accounted for:
Delphi application, Delphi itself, data interfaces (database back end), run time libraries, operating system and last but not the least the hardware.

Borland (Inprise) has stated that Delphi 3, Delphi 4, Delphi 5, Interbase 4.2, Interbase 5, BDE 4.5, and BDE 5 are Y2k compliant. Microsoft has stated that that Dos 6.22, Windows 95, and Windows NT 4.0 (SP3 & SP4) are compliant too. In other words, this means that the following software cannot be used to create Y2K-compliant applications: Delphi versions before Delphi 3 (this means Delphi 1 & 2) and Windows 3.x.
As for the hardware, check for Y2K compliance with the hardware vendor.

   TDateTime - Delphi Date and Time storage
TDateTime, in Delphi, is a used by the date and time routines to hold date and time values. The TDateTime is a double precision IEEE floating point value.
The integral part of a TDateTime value is the number of days that have passed since 12/30/1899. The fractional part of a TDateTime value is the time of day. Note: Delphi 1 calculated the date from year 1, to convert a Delphi 1 date to Delphi 2 date (and beyond), subtract 693594.0 from Delphi 1 date.

//TDateTime values and
//corresponding dates and times
0 		12/30/1899 12:00 am
36298.25 	05/18/1999 06:00 am

The TDateTime type (in fact double real type) can fit about 15-16 significant digits. This is more than enough to represent dates beyond the year 2000.

   Data and Date interfaces
It's obvious that we all are providing some kind of date input interfaces in our (database) Delphi applications. Just to be sure, always try to use four-digit year representation to eliminate century ambiguities. If you have to use two-digits, it must be clear from the context in which century the year is. In printed output always use four-digit years.

If you are writing database applications, the dbedit and grid controls have built in functionality concerning the input of dates. The method that takes care of converting the string data that is typed into a data-aware control is strtodate. The format of dates passed to strtodate is fixed by the date format settings of the Windows environment.
Delphi uses short date mask upon input in database entry fields. The ShortDate variable from the SysUtils unit is taken upon application startup from the short date format in the Regional Settings of the Control Panel and defaults to two-digit years.

You could, however, change (at the beginning of your app.) the ShortDateFormat to something like 'mm/dd/yyyy', unfortunately some of the components you can use are outside the Delphi scope. TDateTimePicker, for instance, is a Microsoft supplied COM control (built into Windows) that uses date format directly from Windows settings. Changing the ShortDateFormat will not affect the TDateTimePicker.

When a two-digit year is passed to strtodate it is assumed to be from the current century. The easiest solution therefore would be to assign an edit mask to the any TDate fields to force entry of a four-digit year.

As for the BDE, the BDE has three means of storing date and time values: date only, time only, and date and time. Delphi VCL is used when converting the date and time values from Delphi application to be stored by the BDE.

   Two digit years and time windows
If you have to use two-digit years, be aware some of the rules:
In Delphi 1, two-digits years XZ are always converted to 19XZ. In Delphi 2 through Delphi 3.02 two digit years XZ are converted to YYXZ, depending on the century digits of the current year. As for now YY is 19, in 2299 YY will be 22. This is known as no time window. This means that after 2000, using two-digit years for input like 05/18/73 would be 05/18/2073, it can't be 05/18/1973.
Fixed time window. Think of some fixed point, like 50. Two-digit years 45 (value less than or equal to fixed point) would be 2045, and value greater than fixed point, let's say 65, imply 1965.
Gliding time window. Delphi 4 has a global variable TwoDigitYearCenturyWindow (in the SysUtils like ShortDateFormat). The default value is 0, so all two-digit years XZ are represented as 19XZ (as for now-we are in 19XZ). Setting TwoDigitYearCenturyWindow to non-zero value causes gliding time window to activate. The "fixed year" is the current year minus TwoDigitYearCenturyWindow value. If this value equals 1949 (TwoDigitYearCenturyWindow:=50, and current year=1999), than all years less then current year (XZ=96) are treated as 20XZ. All years greater or equal to current year are treated as 19XZ.

Don't worry, the World isn't going to collapse! But, be sure not to touch any digital devices :) Nobody really knows yet; we will not know for sure until it has happened.

   Related links/articles

  • The Year 2000 Information Center™ provides a forum for disseminating information about the year 2000 problem, and for the discussion of possible solutions.
  • Inprise Corporation's Year 2000 Web site
  • Microsoft & y2k
  • Delphi year 2000 readiness
  • Addressing Y2K - TwoDigitYearCenturyWindow
  • Borland Database Engine (BDE) Year 2000 Readiness
  • Borland Pascal Time and Date Page
  • Leap Years
  • efg's Computer Lab - Reference Library Dates and Times
  • It’s About Time - Understanding TDateTime, The TDateTime epoch and backwards incompatibility, Working with milliseconds - TTimeStamp, Converting between human readable and TDateTime format, ...

  • What do you think? Post your thoughts and share your views on the Delphi Programming Forum.
  • Discuss Delphi Programming, real time.
  • Just as always, don't wait if you have any questions or comments.
  • Stay in touch with news and views from Delphi Programming; sign up for free newsletter!
  • Start coding the right way. Get yourself a Delphi Programming book!
  • If you want to put a link (text or graphics) to Delphi Programming on your web pages, this is the way to do it.

    Next article: Delphi Online. Learning Delphi Online

    More Features...
    Various Delphi Programming articles sorted by date:
    2000 | 1999 | 1998 or by TOPIC.

    Subscribe to the Newsletter

  • ©2016 About.com. All rights reserved.