Danang Wahyu Nugroho
Danang Wahyu Nugroho

Reputation: 119

How to select data where id and date range timestamp in postgres

I have a problem to make a query for view data in postgresql. I want to view data with 2 condition :

  1. where employeeId
  2. and between daterange

Heres my Query:

Select * 
from employee 
where employeeId = 3 
  and date(created_at) = between '2022-08-29' and '2022-08-31'

I have run that query but show error:

Reason:

SQL Error [42601]: ERROR: syntax error at or near "date" Position: 1`

The type data of column created_at is timestamp. My questions is: What is correct query for view data from that conditions?

Upvotes: 0

Views: 1812

Answers (2)

Ogün Birinci
Ogün Birinci

Reputation: 728

You can use arithmetic operation

Select * 
from employee 
where employeeId = 3 
  and created_at>='2022-08-29' 
  and created_at< '2022-09-01'

Upvotes: 0

Anthony Sotolongo
Anthony Sotolongo

Reputation: 1648

Remove the = operator from your query, the BETWEEN does not require the =

Select * from employee where employeeId = 3 and date(created_at)  between '2022-08-29' and '2022-08-31' 

Upvotes: 2

Related Questions