What's wrong with:
SELECT a,b,c
FROM table
WHERE xtime BETWEEN '2012-04-01 23:55:00'::timestamp
AND now()::timestamp;
If you want to operate with a count of seconds as interval
:
...
WHERE xtime BETWEEN now()::timestamp - (interval '1s') * $selectedtimeParm
AND now()::timestamp;
Note, how I used the standard ISO 8601 date format YYYY-MM-DD h24:mi:ss
which is unambiguous with any locale or DateStyle
setting.
Note also, that the first value for the BETWEEN
construct must be the smaller one. If you don't know which value is smaller use BETWEEN SYMMETRIC
instead.
In your question you refer to the datetime type timestamp
as "date", "time" and "period". In the title you used the term "time frames", which I changed that to "timestamps". All of these terms are wrong. Freely interchanging them makes the question even harder to understand.
That, and the fact that you only tagged the question psql
(the problem hardly concerns the command line terminal) might help to explain why nobody answered for days. Normally, it's a matter of minutes around here. I had a hard time understanding your question, had to read it a couple of times.
You need to understand the data types date
, interval
, time
and timestamp
- with or without time zone. Start by reading the chapter "Date/Time Types" in the manual.
Error message would have gone a long way, too.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…