Delphi version of VB DateAdd

A Delphi implementation of a useful VB function

type

  TDateAddUnit = (daYears, daMonths, daDays);



function DateAdd(ADate: TDateTime; Quantity: Integer; AUnit: TDateAddUnit): TDateTime;

var

  TimePart: TDateTime;

begin

  Result := Trunc(ADate);

  TimePart := ADate - Trunc(ADate);

  case AUnit of

    daYears:

      IncMonth(ADate, 12 * Quantity);



    daMonths:

      IncMonth(ADate, Quantity);

  else

    Result := ADate + Quantity;

  end;

  Result := Result + TimePart;

end;

 

Share this article!

Follow us!

Find more helpful articles:

Comments

Mar
12

This function seems very usefull but when i copy the code i have this error."Undeclared identifier TDateAddUnit"......what exactly is TDateAddUnit ...and how to use it

please help

By ardita metushi