Description |
The IncDay function returns a TDateTime value that is NumberOfDays greater than the passed StartDateTime value.
The year and month values are incremented as appropriate.
The increment value is optional, being 1 by default.
|
|
Notes |
There is no DecDay function.
Instead, use IncDay with a negative increment.
|
|
Related commands |
IncMinute |
|
Increments a TDateTime variable by + or - number of minutes |
IncMonth |
|
Increments a TDateTime variable by a number of months |
IncYear |
|
Increments a TDateTime variable by a number of years |
IncSecond |
|
Increments a TDateTime variable by + or - number of seconds |
IncMillisecond |
|
Increments a TDateTime variable by + or - number of milliseconds |
|
|
|
Example code : A simple example of increment and decrement |
// Full Unit code. // ----------------------------------------------------------- // You must store this code in a unit called Unit1 with a form // called Form1 that has an OnCreate event called FormCreate. unit Unit1; interface uses DateUtils, // Unit containing the IncDay command SysUtils, Forms, Dialogs; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} // Include form definitions procedure TForm1.FormCreate(Sender: TObject); var
myDate : TDateTime;
begin // Set up our date just before the end of the year 2000
myDate := EncodeDate(2000, 12, 30);
ShowMessage('myDate = '+DateToStr(myDate));
// Add 10 days to this date
myDate := IncDay(myDate, 10);
ShowMessage('myDate + 10 days = '+DateToStr(myDate));
// Subtract 12 days from this date
myDate := IncDay(myDate, -12);
ShowMessage('myDate - 12 days = '+DateToStr(myDate));
end; end.
|
Hide full unit code |
myDate = 30/12/2000
myDate + 10 days = 09/01/2001
myDate - 12 days = 29/12/2000
|
|