Delphi Pages Forums

Delphi Pages Forums (
-   General (
-   -   How to check a correct date? (

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,

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;
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
Result := True;
Result := False;
end; {try}


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.