Search Postgresql Archives

Re: storing repeating dates / events

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



rkmr.em@xxxxxxxxx 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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux