Code Snippets → Find Earliest Date From Input

Function ReturnEarliestDate(strInput As String, strDelimiter As String) As Date
' Usage:
' In a query pass the dates in as a string with whatever delimiter you want. 
' For example, with a pipe it would be:
' ReturnEarliestDate([DateField1] & "|" & [DateField2] & "|" & [DateField3] & "|" & [DateField4], "|") AS OldestDate
'
' It will return a single date - the earliest of the inputted dates.  So, if the string ends up like:
' "1/2/2010|2/22/2010|4/2/1998|1/2/1998"
' the returned value would be 1/2/1998

    Dim varSplit As Variant
    Dim i As Integer
    Dim dteHold As Date
    varSplit = Split(strInput, strDelimiter, , vbTextCompare)
    dteHold = varSplit(i)
    For i = LBound(varSplit) To UBound(varSplit)
        If i > 0 Then
            If varSplit(i) <> vbNullString Then
               If CDate(varSplit(i)) < dteHold Then
                   dteHold = CDate(varSplit(i))
               End If
            End If
        End If
    Next i
    ReturnEarliestDate = dteHold
End Function