Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Get the Age of an Email in Days

See more Email Object Examples

Demonstrates the read-only Chilkat Email.NumDaysOld property, which returns how many days old the email is, measured from the Date header relative to the current system date/time. If the Date header is missing or invalid, -9999 is returned; a negative value (other than -9999) means the Date header is in the future. This example sets a Date header and prints the computed age.

Background: The age is derived from the message's own Date header — the timestamp the sender wrote into the email — not from when you downloaded or loaded it. This is handy for tasks like "delete messages older than 30 days," but keep in mind the Date header is set by the sender and can be inaccurate or spoofed. The sentinel value -9999 is how Chilkat signals it could not parse a valid date at all.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.Email;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  email: TEmail;

begin
  //  Demonstrates the read-only Email.NumDaysOld property.  It returns the age of the
  //  email in days, computed from the Date header relative to the current system time.
  //  It returns -9999 if the Date header is missing or invalid, and can be negative
  //  if the Date header is in the future.

  email := TEmail.Create;

  //  Set the Date header.  NumDaysOld is computed from this value.
  email.EmailDateStr := 'Wed, 01 Jul 2026 12:00:00 GMT';

  WriteLn('NumDaysOld = ' + email.NumDaysOld);


  email.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.