Option Public
Option Declare

Sub Initialize
	Dim s As New NotesSession
	Dim db As NotesDatabase							' this db
	Dim col As NotesDocumentCollection			' all docs in db
	Dim doc As NotesDocument						' current doc
	Dim nDoc As NotesDocument						' doc after next doc
	Dim dopurge As Integer								' purge flag for compact
	
	' get all docs
	Set db = s.CurrentDatabase
	Set col = db.AllDocuments
	Set doc = col.GetFirstDocument()
	Print "Looping ..."
	While Not (doc Is Nothing)
		' get next doc
		Set nDoc = col.GetNextDocument(doc)
		' see if older than cut
		If (TestIfDocOlder(doc, 12)=1) Then
			' delete doc
			Call doc.Remove(True)
			dopurge =1
		End If
		' loop
		Set doc = nDoc
	Wend
	' do compact if doc deleted
	If (dopurge=1) Then
		Print "Compacting .... "
		Call db.CompactWithOptions(8)			' compact w/space reduction
	End If
	Print "Done."
End Sub

Function TestIfDocOlder(doc As NotesDocument, daysnum As Integer) As Integer
	' return 1 for yes/older, 0 for no
	Dim cutNDT As NotesDateTime
	Dim docNDT As NotesDateTime
	
	TestIfDocOlder = 0
	
	Set cutNDT = New NotesDateTime( "Today" )
	Set docNDT = New NotesDateTime( "" )
	Call cutNDT.AdjustDay( -1 * daysnum )											' adjust days back
	docNDT.LSLocalTime = doc.LastModified
	If cutNDT.TimeDifferenceDouble( docNDT ) > 0  Then
		TestIfDocOlder = 1
		Exit Function
	End If
	
End Function