Delphi DateTimeFormat returning wrong year
Posted
by Leslie
on Stack Overflow
See other posts from Stack Overflow
or by Leslie
Published on 2010-04-15T17:58:05Z
Indexed on
2010/04/15
18:13 UTC
Read the original article
Hit count: 302
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:
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
© Stack Overflow or respective owner