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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Greatest Date???

Status
Not open for further replies.

bakerm

Programmer
Apr 25, 2000
53
US
I have three seperate dates that are returned in a recordset. My dilema: Is there a niffty vb function that will allow me to get the most recent of the three dates in just a line or two of code as opposed to several if...else statements.

As usaul your help is greatly appreciated!!!
 
If you want to put the code into one line, you can use IIF(condition,True,False) and then nest IIF statements into the True and False sections.

Consider the DateFields Date1, Date2, Date3. You want to compare them and return the highest into the field MaxDate:

SELECT Date1, Date2, Date3, IIF(Date1>=Date2,IIF(Date1>=Date3,Date1,Date3),IIF(Date2>=Date3,Date2,Date3)) AS MaxDate FROM table_Name

This can be done in the sql statement that your recordset is based on. (provided you are doing it this way).

Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top