How to ensure a date entered is correct, and if not then fix it.

function FixDate(YYYY, MM, DD: Word): TDateTime;


  if DD < 1 then DD := 1;

  if MM < 1 then MM := 1;

  if YYYY < 1 then YYYY := 1;

  Result := -1;

  while DD > 0 do


    Result := EncodeDate(YYYY, MM, DD);

    //It worked, we can stop now



    //Date was not valid, try the day before





Share this article!

Follow us!

Find more helpful articles: