Function KeepLaterDate(compNDT As NotesDateTime, curDoc As NotesDocument) As NotesDateTime
	' returns the later date, the compare date object or the last mod date in the passed doc
	Dim tmpNDT As NotesDateTime			' temp working variable
	
	On Error Goto FErrorHandler
	
	' check empty doc
	If (curDoc Is Nothing) Then
		Set KeepLaterDate = compNDT
		Exit Function
	End If
	' get curDoc's last mod datetime
	Set tmpNDT = New NotesDateTime(curDoc.LastModified)
	
	' check nothing compare date
	If (compNDT Is Nothing) Then
		' use doc's time
		Set KeepLaterDate = tmpNDT
		Exit Function
	End If
	
	' both dates exist see which one is later
	If (tmpNDT.TimeDifferenceDouble(compNDT)<0) Then
		' if left side is earlier than right side, right side is later, return right side
		Set KeepLaterDate = compNDT
	Else
		' left side is later than right side, return left side
		Set KeepLaterDate = tmpNDT
	End If
FExit:
	Exit Function
	
FErrorHandler:
	Print "(KeepLaterDate) Error: " & Cstr(Err) & " " & Error$ & ", line: " & Cstr(Erl) & "."
	Set KeepLaterDate = compNDT
	Resume FExit
End Function