Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FormatDateTime returning wrong year

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
0
0
US
I have a form that allows users to enter a date of birth:

ie: 4/16/40

Then when the user processes the form there's a function that checks it's length, adds leading zeros, parses the date and then uses FormatDateTime to just return the year of birth:
Code:
strTemp := strPostedByDOB;
If Length(strTemp) = 5
  then strTemp = '0' + strTemp;
if Length(strTemp) = 6 
  then begin
    strTemp := Copy(strTemp, 1 ,2) + '/' + copy(strTemp, 3, 2) + '/' + Copy(strTemp, 5, 2);
    strTemp := FormatDateTime('YYYY', StrToDate(strTemp));
end
else strTemp := EmptyStr;
using this code the strTemp is calculated as 2040 instead of 1940. Can anyone help me figure out how to make it show 1940 in strTemp? Do I have to change the form to accept a 4 digit year?

Thanks, Leslie

Leslie
 
Got an answer - now using the TwoDigitYearCenturyWindow and it's working fine!

Leslie
 
Hmmm... I'm still playing with it. Using:
Code:
  GetLocaleFormatSettings(0, FormatSettings);
  FormatSettings.TwoDigitYearCenturyWindow:= SomeValue;
  strTemp:= FormatDateTime('YYYY', StrToDate(strTemp), FormatSettings);
What did you have to plug into 'SomeValue' to get it to work???

Roo
Delphi Rules!
 
As a rule, any project I work on must use and display 4-digit years. It wasn't just about preserving memory and storage space when the rule of thumb for programmers was to just use 2-digit years. It was also because the recorded data programs had available to them to search and report on was pretty much limited to the 1900s too.

Now that we're well into the 21st century, it seems short-sighted for any program to not require a 4-digit year for data entry and display.
 
yes but this program was written a while ago and would take major code modifications to change it to a four digit year. roo here's a link to the solution i used.

Leslie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top