Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Thread Tools Display Modes
Old 03-10-2002, 12:36 PM
Luke Luke is offline
Senior Member
Join Date: Feb 2001
Posts: 359
Default 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,
Reply With Quote
Old 03-10-2002, 03:13 PM
HTML HTML is offline
Senior Member
Join Date: Jan 2001
Posts: 2,977
Default 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.
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump

All times are GMT. The time now is 03:55 AM.

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