query the latest date out of two?

M

matjcb

I have a table with two dates

I would like to query the latest date of the two.

Date 1 Date 2 have it return
07/01/08 08/01/08 08/01/08

Thanks
 
J

John Spencer

If you mean you want to return the latest date

Field: IIF([Date 1] > [Date 2],[Date 1],[Date 2])

That does run into a bit of a problem if one of the two is null. To handle
that possibility you could use

IIF(Nz([Date 1],#1/1/1850#) > Nz([Date 2],#1/1/1850#),[Date 1],[Date 2])



John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
 
J

John Spencer

A slightly simpler expression for handling null dates.

IIF([Date 1] > [Date 2],[Date 1],Nz([Date 2],[Date 1])

John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County

John said:
If you mean you want to return the latest date

Field: IIF([Date 1] > [Date 2],[Date 1],[Date 2])

That does run into a bit of a problem if one of the two is null. To
handle that possibility you could use

IIF(Nz([Date 1],#1/1/1850#) > Nz([Date 2],#1/1/1850#),[Date 1],[Date 2])



John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
I have a table with two dates

I would like to query the latest date of the two.

Date 1 Date 2 have it return 07/01/08 08/01/08
08/01/08

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top