Sample code for 30+ languages & platforms
Delphi ActiveX

Date/Time Expires Within N Seconds/Minutes/Hours/Days

Demonstrates the how to tell if a date/time is within N seconds, minutes, hours, or days of the current system time.

Chilkat Delphi ActiveX Downloads

Delphi ActiveX
uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Chilkat_TLB;

...

procedure TForm1.Button1Click(Sender: TObject);
var
dt: TCkDateTime;
b: Integer;

begin
dt := TCkDateTime.Create(Self);

// Set to the current system date/time.
dt.SetFromCurrentSystemTime();
Memo1.Lines.Add('Now: ' + dt.GetAsTimestamp(1));

// Add 10 minutes, making the date 10 minutes in the future.
dt.AddSeconds(600);
Memo1.Lines.Add('10 minutes from now: ' + dt.GetAsTimestamp(1));

// Is the date/time within 10 seconds of expiration (i.e. within 10 seconds of now)?
b := dt.ExpiresWithin(10,'seconds');
Memo1.Lines.Add('Expires within 10 seconds: ' + IntToStr(Ord(b)));

// Does the date/time expire within 5 minutes?
b := dt.ExpiresWithin(5,'minutes');
Memo1.Lines.Add('Expires within 5 minutes: ' + IntToStr(Ord(b)));

// Does the date/time expire within 15 minutes?
b := dt.ExpiresWithin(15,'minutes');
Memo1.Lines.Add('Expires within 15 minutes: ' + IntToStr(Ord(b)));

// Does the date/time expire within 1 hour?
b := dt.ExpiresWithin(1,'hour');
Memo1.Lines.Add('Expires within 1 hour: ' + IntToStr(Ord(b)));

// Does the date/time expire within 1 day?
b := dt.ExpiresWithin(1,'day');
Memo1.Lines.Add('Expires within 1 day: ' + IntToStr(Ord(b)));

// Output:

// 	Now: 2017-05-05T23:48:00-0500
// 	10 minutes from now: 2017-05-05T23:58:00-0500
// 	Expires within 10 seconds: False
// 	Expires within 5 minutes: False
// 	Expires within 15 minutes: True
// 	Expires within 1 hour: True
// 	Expires within 1 day: True
end;