DelphiBasics
IncMillisecond
Function
Increments a TDateTime variable by + or - number of milliseconds DateUtils unit
 function IncMillisecond ( const StartDateTime : TDateTime {; NumberOfMilliSeconds : Integer = 1} ) : TDateTime;
Description
The IncMillisecond function returns a TDateTime value that is NumberOfMilliSeconds 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 DecMillisecond function.

Instead, use IncMillisecond with a negative increment.
Related commands
IncYear Increments a TDateTime variable by a number of years
IncMonth Increments a TDateTime variable by a number of months
IncDay Increments a TDateTime variable by + or - number of days
IncMinute Increments a TDateTime variable by + or - number of minutes
IncSecond Increments a TDateTime variable by + or - number of seconds
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 Download this web site as a Windows program.




 
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 IncMillisecond 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 to the start of 2006
  myDate := EncodeDateTime(2006, 1, 1, 0, 0, 0, 0);
  ShowMessage('myDate = '+DateTimeToStr(myDate));

  // Add 5000 milliseconds to this date
  myDate := IncMillisecond(myDate, 5000);
  ShowMessage('myDate + 5000 milliseconds = '+DateTimeToStr(myDate));

  // Subtract 2000 milliseconds from this date
  myDate := IncMillisecond(myDate, -2000);
  ShowMessage('myDate -  2000 milliseconds = '+DateTimeToStr(myDate));
end;
 
end.
Hide full unit code
   myDate = 01/01/2006
   myDate = 01/01/2006 00:00:05
   myDate = 01/01/2006 00:00:03
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Home Page