Delphi Pages Forums

Delphi Pages Forums (http://www.delphipages.com/forum/index.php)
-   General (http://www.delphipages.com/forum/forumdisplay.php?f=2)
-   -   How to check a correct date? (http://www.delphipages.com/forum/showthread.php?t=48299)

Luke 03-10-2002 12:36 PM

How to check a correct date?
 
Hi to all,


I would like to write a function that inform me if the date typed by the user is correct or not. Format date is dd/mm/yyyy. So the first 2 numbers between 1 and 31, then '/', 3 and 4 number between 1 and 12 and the last 4 number for example between 1900 and 2010.
Any ideas to develope this function that gives to me if the date insered ic correct??

Thanks to all for the collaboration,
Luke

HTML 03-10-2002 03:13 PM

RE: How to check a correct date?
 
Hello, Luke

This will work for your need.

{---------------------------------------------------------}
function IsDateValid( ADateStr:string ):boolean;
begin
if Length(ADateStr)=10 then {length must be 10}

{checks that both slashes should be in correct places}
if (Copy(ADateStr,3,1)='/') AND (Copy(ADateStr,6,1)='/') then
try
StrToDate(ADateStr);
Result := True;
except
Result := False;
end; {try}

end;
{---------------------------------------------------------}



But just a note, if you use a string that will have letters the debugger will throw a exception. But not during runtime becuase of try block.


All times are GMT. The time now is 12:39 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.