Sample code for 30+ languages & platforms
Android™

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 Android™ Downloads

Android™
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

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

    CkEmail email = new CkEmail();

    //  Set the Date header.  NumDaysOld is computed from this value.
    email.put_EmailDateStr("Wed, 01 Jul 2026 12:00:00 GMT");

    Log.i(TAG, "NumDaysOld = " + String.valueOf(email.get_NumDaysOld()));

  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}