Sample code for 30+ languages & platforms
DataFlex

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 DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoEmail
    Integer iTemp1

    //  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.

    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End

    //  Set the Date header.  NumDaysOld is computed from this value.
    Set ComEmailDateStr Of hoEmail To "Wed, 01 Jul 2026 12:00:00 GMT"

    Get ComNumDaysOld Of hoEmail To iTemp1
    Showln "NumDaysOld = " iTemp1


End_Procedure