From: | Taras Kopets <tkopets(at)gmail(dot)com> |
---|---|
To: | "rkmr(dot)em(at)gmail(dot)com" <rkmr(dot)em(at)gmail(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: storing repeating dates / events |
Date: | 2008-09-07 00:39:08 |
Message-ID: | 48C322AC.9040605@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
rkmr(dot)em(at)gmail(dot)com wrote:
> Hi
> I want to store dates / events for example birthdays (or may 5th) that
> repeats every year..
> what is the best way to do in postgres?
> if i use timestamp it is going to be use the current year.. how do i
> do this?
Any anniversary today?
SELECT *
FROM your_table_with_timestamp_column
WHERE EXTRACT(DAY FROM your_column) = EXTRACT(DAY FROM now())
AND EXTRACT(MONTH FROM your_column) = EXTRACT(MONTH FROM now())
AND your_column <= now(); -- prevent to show events that will
be in the future
Or May 5th:
SELECT *
FROM your_table_with_timestamp_column
WHERE EXTRACT(DAY FROM your_column) = EXTRACT(DAY FROM TIMESTAMP
'2008-05-05')
AND EXTRACT(MONTH FROM your_column) = EXTRACT(MONTH FROM TIMESTAMP
'2008-05-05')
AND '2008-05-05'::timestamp <= now(); -- prevent to show
events that will be in the future
Sorry, if I misunderstood your question.
Taras Kopets
From | Date | Subject | |
---|---|---|---|
Next Message | Randal T. Rioux | 2008-09-07 03:59:06 | Re: 64-bit Compile Failure on Solaris 10 with OpenSSL |
Previous Message | Tom Lane | 2008-09-07 00:21:12 | Re: 64-bit Compile Failure on Solaris 10 with OpenSSL |