Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing Date variables

Status
Not open for further replies.

jlrrush

MIS
Joined
Aug 3, 2004
Messages
9
Location
US
Is there are function that exists that allows me to compare a number of different date variables, that may or maynot be null, the output being the max date of the variables.

For example:
Var 1: 2/21/2006
Var 2: null
Var 3: 2/15/2006
Var 4: 2/15/2005

And I would expect get the date of 2/21/2006.
 
Where are Var 1, ..., Var 4 coming from ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
The vars are all coming from the same table.
 
There is this
Code:
Public Function MaxVal(ParamArray Vals() As Variant) As Variant
    Dim X                           As Variant
    Dim MV                          As Variant
    Dim Initialized                 As Boolean
    For Each X In Vals
        If Not Initialized and Not IsNull(X) Then
            Initialized = True
            MV = X
        End If
        If Not IsNull(X) And X > MV Then MV = X
    Next
    MaxVal = MV

End Function
That you would just call with SQL of the form
Code:
Select MaxVal([Var 1], [Var 2], [Var 3], [Var 4]) As MaxDate, etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top