Date validation

hi,

i need to validate dates so that my START date cannot be in the past
and my END date cannot be before the start date.

i am using Datepickers for both dates.

i know i have to use the 'NOW' function but i'm not entirely sure how it works.

thanks

Comments

  • you can use > < = on dates. if StrToDate('15/08/1978') < Date then ShowMessage('ok');

  • : hi,
    :
    : i need to validate dates so that my START date cannot be in the past
    : and my END date cannot be before the start date.
    :
    : i am using Datepickers for both dates.
    :
    : i know i have to use the 'NOW' function but i'm not entirely sure how it works.
    :
    : thanks
    :
    try this
    [code]
    function CheckDate(StartDate, EndDate : TDateTime): Boolean;
    begin
    result := False;
    if EndDate < StartDate // Check EndDate greater than StartDate
    then Exit;
    if StartDate < Now // Check StartDate is in future
    then Exit;

    // If the program gets here the tests are passed, so result is True
    result := True;
    end;
    [/code]
    just insert the function somewhere in your program and call as needed

    [code]
    if not CheckDate(StartDate,EndDate)
    then ShowMessage ('Illegal Date(s) entered');
    [/code]



    HTH

    Richard.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories