Re: Date searching by month & day only

From: Chris Campbell <ccampbell(at)cascadeds(dot)com>
To: Steve Crawford <scrawford(at)pinpointresearch(dot)com>, "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Date searching by month & day only
Date: 2012-03-13 22:16:30
Message-ID: 453A24085F801842AEA8D0B6B269065D020B2D909A0A@HDMC.cds.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

>> I'm attempting to pull up a birthday list of anyone born between,
>> let's say June 15 and June 30^th . The year is irrelevant.
>>
>> I'm wondering if there is a more elegant way to do this than using
>> something like:
>>
>> SELECT key, dob from ds1.contact
>>
>> WHERE
>>
>> extract(month FROM contact.dob ) = 6
>>
>> and extract(day FROM contact.dob) >= 15
>>
>> and extract(day FROM contact.dob) <= 30
>>
>>
>One thing to consider is whether the rest of your query combined with the size of your table will require the ability to use an >index to speed the query.

>Here is one possibility
>SELECT ... WHERE to_char(contact.dob, 'MMDD') between '0615' and '0630'...
>If necessary, you can index on (to_char(contact.dob, 'MMDD')).
>Cheers,
>Steve

I like it! Thank you Steve for your suggestion.

--
Sent via pgsql-novice mailing list (pgsql-novice(at)postgresql(dot)org) To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-novice

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Rory Campbell-Lange 2012-03-13 23:01:01 Re: QUERY
Previous Message Steve Crawford 2012-03-13 22:09:22 Re: Date searching by month & day only