Howdy, Stranger!

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

Categories

Date validation

drlawdrlaw Member Posts: 11
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

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

  • RickListRickList Member Posts: 22
    : 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.

  • Shawn CarterShawn Carter Member Posts: 0

    _ | http://forcoder.org | free ebooks and video tutorials about || Scratch, Swift, Perl, Ruby, Assembly, Delphi, Go, Python, C++, MATLAB, R, JavaScript, C#, PL/SQL, PHP, Java, Visual Basic .NET, C, Visual Basic, Objective-C Crystal, Transact-SQL, Apex, ABAP, VBScript, SAS, Prolog, ML, Awk, Dart, Kotlin, Rust, Fortran, Lua, Clojure, Lisp, Scheme, COBOL, Alice, Julia, Erlang, Hack, Ada, D, LabVIEW, Bash, FoxPro, Logo, F#, Scala || _____

Sign In or Register to comment.