Description |
The TwoDigitYearCenturyWindow variable is used when converting 2 digit year date strings to TDateTime values.
The TwoDigitYearCenturyWindow value is subtracted from the current date to set the conversion threshold.
For example :
TwoDigitYearCenturyWindow | : 50 (default) |
Current year last | : 2002 |
Threshold is then set | : 1952 |
100 year window becomes | : 1952 - 2051 |
When converting a 2 digit string year, such as 75, the 2 digits are compared to the threshold last two digits. If greater, then the date is in the lower century, for example 1975. If lower than the threshold, the date is in the higher century. For example, 44 would give 2044.
|
|
Notes |
If the TwoDigitYearCenturyWindow value is zero, then the value is always set in the current century, regardless of the 2 digits value.
|
|
Related commands |
StrToDate |
|
Converts a date string into a TDateTime value |
StrToDateTime |
|
Converts a date+time string into a TDateTime value |
|
|
|
Example code : Move the threshold to see how a conversion is affected |
// Full Unit code. // ----------------------------------------------------------- // You must store this code in a unit called Unit1 with a form // called Form1 that has an OnCreate event called FormCreate. unit Unit1; interface uses SysUtils, // Unit containing the TwoDigitYearCenturyWindow command DateUtils, Forms, Dialogs; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} // Include form definitions procedure TForm1.FormCreate(Sender: TObject); var
myDate : TDateTime;
formattedDate : string;
begin // Set up a date from a 2 digit year using the default threshold
myDate := StrToDate('09/05/30');
ShowMessage('09/05/30 using default threshold = '+DateToStr(myDate));
// Now change the default threshold to 80 : // 2002 (at time of writing) - 80 gives 1922 // 30 is above 22, so 1900 century is chosen
TwoDigitYearCenturyWindow := 80;
myDate := StrToDate('09/05/30');
ShowMessage('09/05/30 using override threshold = '+DateToStr(myDate));
end; end.
|
Hide full unit code |
09/05/30 using default threshold = 09/05/2030
09/05/30 using override threshold = 09/05/1930
|
|