VBScript
VBScript
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 VBScript Downloads
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)
' 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.
set email = CreateObject("Chilkat.Email")
' Set the Date header. NumDaysOld is computed from this value.
email.EmailDateStr = "Wed, 01 Jul 2026 12:00:00 GMT"
outFile.WriteLine("NumDaysOld = " & email.NumDaysOld)
outFile.Close