DelphiBasics
IncSecond
Function
Increments a TDateTime variable by + or - number of seconds DateUtils unit
 function IncSecond(const StartDateTime TDateTime {; NumberOfSeconds Integer = 1}):TDateTime;
Description
The IncSecond function returns a TDateTime value that is NumberOfSeconds greater than the passed StartDateTime value.
 
The year, month, day and hour values are incremented as appropriate.
 
The increment value is optional, being 1 by default.
Notes
There is no DecSecond function.

Instead, use IncSecond with a negative increment.
Related commands
IncYearIncrements a TDateTime variable by a number of years
IncMonthIncrements a TDateTime variable by a number of months
IncDayIncrements a TDateTime variable by + or - number of days
IncMinuteIncrements a TDateTime variable by + or - number of minutes
IncMillisecondIncrements a TDateTime variable by + or - number of milliseconds
 Download this web site as a Windows program.




 
Example code : A simple example of increment and decrement
var
  myDate : TDateTime;
begin
  // Set up our date just before the end of the year 2005
  myDate := EncodeDateTime(2005, 12, 31, 23, 59, 0, 0);
  ShowMessage('myDate = '+DateTimeToStr(myDate));

  // Add 60 seconds to this date
  myDate := IncSecond(myDate, 60);
  ShowMessage('myDate +  60 seconds = '+DateTimeToStr(myDate));

  // Subtract 120 seconds from this date
  myDate := IncSecond(myDate, -120);
  ShowMessage('myDate - 120 seconds = '+DateTimeToStr(myDate));
end;
Show full unit code
  myDate = 31/12/2005 23:59:00
  myDate + 60 seconds = 01/01/2006
  myDate - 120 seconds = 31/12/2005 23:58:00
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page