Re: Selecting the most recent date

From: Dennis Gearon <gearond(at)cvc(dot)net>
To: Mark Tessier <m_tessier(at)sympatico(dot)ca>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Selecting the most recent date
Date: 2003-04-28 18:21:08
Message-ID: 3EAD7114.50002@cvc.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

select (rows desired)
from tableselect
where abs( todays_date - col_date) = min( abs( todays_date - col_date));

SORT OF <LOL>, I'm not sure how to find that particular row, but is how you find the minimum difference from todays date.

Mark Tessier wrote:
> Hi,
>
> My question is hopefully a simple one: If I have several rows, each containing a date field, and I want to select the row that has the date closest to today's date, what would be the syntax for carrying that out.
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Dennis Gearon 2003-04-28 18:22:28 Re: problems restoring 7.2.1 dump to 7.3.2
Previous Message Robert Fitzpatrick 2003-04-28 18:09:21 Re: Setting a field to default if blank value