DelphiBasics
TwoDigitYearCenturyWindow
Variable
Sets the century threshold for 2 digit year string conversions SysUtils unit
  var TwoDigitYearCenturyWindow : Word;
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
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 Download this web site as a Windows program.


 
Example code : Move the threshold to see how a conversion is affected
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;
Show full unit code
   09/05/30 using  default threshold = 09/05/2030
   09/05/30 using override threshold = 09/05/1930
 
Delphi Programming Neil Moffatt 2002 - 2016. All rights reserved.  |  Home Page