Yuqing
Yuqing

Reputation: 343

PostgreSQL select a fixed time intervals from a range of days defined in timestamp

The time data in my database is stored using timestamp. I want to select a fixed time intervals from a range of days. For example, select the tuples that has timestamp that satisfies: its time is between 2pm and 3pm, and its date is between 2015-01-01 and 2015-01-31.

SELECT * FROM data WHERE ????time???? ;

In plain English select the data that are recorded between 2pm and 3pm for January.

Any suggestions?

Upvotes: 0

Views: 370

Answers (1)

krokodilko
krokodilko

Reputation: 36107

Try

SELECT * FROM data 
WHERE time_column BETWEEN date '2015-01-01' AND date '2015-01-31'
  AND extract( hour from time_column ) BETWEEN 14 AND 15 ;

Upvotes: 1

Related Questions